4
我試圖檢測兩個觸摸我的兩個imagebuttons是單一的相對佈局。 問題是它在兩個按鈕上顯示action_down值,但沒有動作指針向下值。android多點觸摸,動作指針向下不能正常工作
我的代碼如下:
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" />
添加**返回true;賦予true值後,**你OnTouch方法.. – Numair 2013-03-01 11:51:12
,問題依舊不變。 – 2013-03-01 12:18:39
然後發佈你的代碼,你的onTouch方法沒有問題。 – Numair 2013-03-01 12:32:22