我试图检测我的两个图像按钮上的两次触摸,这是单个相对布局。问题是它在两个按钮上显示 action_down 值,但没有动作指针向下值。
我的代码如下:
private int getIndex(MotionEvent event) {
int idx = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
return idx;
}
@Override
public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
// TODO Auto-generated method stub
// Boolean state=false;
// int pointerCount = paramMotionEvent.getPointerCount();
boolean val = false;
int pointerIndex = paramMotionEvent.getAction() & MotionEvent.ACTION_MASK;
switch(pointerIndex)
{
case MotionEvent.ACTION_DOWN :{
Log.i("fil", "action dowm");
break;
}
case MotionEvent.ACTION_POINTER_DOWN :{
int id = paramMotionEvent.getPointerId(getIndex(paramMotionEvent));
Log.d("fil", "Other point down ["+id+"]");
Log.i("fil", "action pointer down");
break;
}
case MotionEvent.ACTION_POINTER_UP :{
int id = paramMotionEvent.getPointerId(getIndex(paramMotionEvent));
Log.d("fil", "Other point down ["+id+"]");
Log.i("fil", "action pointer up");
break;
}
case MotionEvent.ACTION_UP :{
Log.i("fil", "action up");
break;
}
}
'my xml'
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
</RelativeLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:background="@drawable/ic_launcher" />