문제

I'm somehow getting unexpected results while trying to implement multitouch in my app. I'm never getting data for more than one pointer. Multitouch on my phone surely works, because I can pinch-zoom in browser and detect pinch gesture with GestureDetector, but the following sample prints action=0 pointers=1 regardless of how many fingers I use to touch the screen.

Is there something in configuration/AndroidManifest or Activity creation that I need to

@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;
        }
    });
}

layout:

<?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>
도움이 되었습니까?

해결책

The problem was that I was returning false in onTouch, therefore new touch events have not been generated.

다른 팁

In my case, I realized that getPointerCount() was not changing because it was being called inside the MotionEvent.ACTION_DOWN action which meant it'd always be one.

The solution was to move it, either to MotionEvent.ACTION_MOVE if the pointer count is needed on move, either outside of the actions, to the onTouch implementation if the pointer count is needed once on touch. I hope this helps someone who may not have understood this as in my case.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top