MotionEvent杰蒂()和信息getX()返回不正确的值 [英] MotionEvent GetY() and getX() return incorrect values

查看:369
本文介绍了MotionEvent杰蒂()和信息getX()返回不正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况:

我有一个自定义的ListView用的ImageView和TextView的一排。 ImageView的有onTouchListener,wchich调用我的onTouch方法。这里有一些线路从它:

I have a custom ListView with ImageView and TextView in a row. The ImageView has an onTouchListener, wchich invokes my onTouch method. Here are some lines from it:

if (event.getAction()==MotionEvent.ACTION_MOVE) {
    layout.leftMargin = (int) event.getX() - dragIcon.getWidth()/2;         
    layout.topMargin = (int) event.getY() - dragIcon.getHeight()/2;
    //Log.d("Tag", "Pozycja: " +  event.getX() +", "+  event.getY());
}
dragIcon.setLayoutParams(layout);

当检测到移动我展示了新的形象(这不是ListView中)和我开始根据x和y坐标来移动它。

When move is detected I'm showing up new image (not this in ListView) and I'm starting to move it according to x and y coordinates.

的问题是,相对于ImageView的列表中的getX和回报的getY位置,而不是整个的ListView(我认为是这样)。所以,当我在中间,轻扫手指触摸项目,然后返回的getY负值(以上ImageView的边界)。

The problem is, that getX and getY return positions relative to ImageView in the list, not the whole ListView (I think so). So when I touch an item in the middle and swipe finger up, then getY returns negative values (above ImageView boundary).

希望,我解释清楚。

任何想法如何得到这个坐标相对于屏幕大小? 谢谢你。

Any ideas how to get this coordinates relative to the screen size? Thank you.

推荐答案

尝试使用 getRawX() getRawY()代替的getX() getY()以

这篇关于MotionEvent杰蒂()和信息getX()返回不正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆