获取其他指针MotionEvent.getRawX / getRawY [英] Get MotionEvent.getRawX/getRawY of other pointers

查看:214
本文介绍了获取其他指针MotionEvent.getRawX / getRawY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能否获得其他指针MotionEvent.getRawX()/ getRawY()的值?

Can I get the value of MotionEvent.getRawX()/getRawY() of other pointers ?

<一个href="http://developer.android.com/reference/android/view/MotionEvent.html#getRawX%28%29">MotionEvent.getRawX()参考

该API表示,使用getRawX / getRawY获得原生X / Y坐标,但它仅用于1指针(最后触摸的指示器),是有可能得到其他指针的原始X / Y坐标?

The api says that uses getRawX/getRawY to get original raw X/Y coordinate, but it only for 1 pointer(the last touched pointer), is it possible to get other pointer's raw X/Y coordinate ?

推荐答案

事实上,API不允许这样做,但你可以计算它。尝试:

Indeed, the API doesn't allow to do this, but you can compute it. Try that :

public boolean onTouch(final View v, final MotionEvent event) {

    int rawX, rawY;
    final int actionIndex = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
    final int location[] = { 0, 0 };
    v.getLocationOnScreen(location);
    rawX = (int) event.getX(actionIndex) + location[0];
    rawY = (int) event.getY(actionIndex) + location[1];

}

这篇关于获取其他指针MotionEvent.getRawX / getRawY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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