14

尝试在我的应用程序中实现多点触控时,我以某种方式得到了意想不到的结果。我永远不会获得超过一个指针的数据。我的手机上的多点触控确实有效,因为我可以在浏览器中进行捏合缩放并使用 GestureDetector 检测捏合手势,但action=0 pointers=1无论我用多少手指触摸屏幕,都会打印以下示例。

我需要在配置/AndroidManifest 或 Activity 创建中做些什么

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    findViewById(R.id.ll1).setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.d("TAG","onTouch action="+event.getAction()+" pointers="+event.getPointerCount());
            return false;
        }
    });
}

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
</LinearLayout>
4

2 回答 2

30

问题是我正在返回falseonTouch因此尚未生成新的触摸事件。

于 2012-07-29T14:23:36.667 回答
2

就我而言,我意识到这getPointerCount()并没有改变,因为它在动作内部被调用,MotionEvent.ACTION_DOWN这意味着它永远是一个。

解决方案是将它移动到移动时MotionEvent.ACTION_MOVE需要指针计数,或者在动作之外,如果在触摸时需要指针计数,则移动到 onTouch 实现。我希望这可以帮助那些可能不像我这样理解这一点的人。

于 2019-04-23T06:10:23.523 回答