0

根据文档,我提出了以下内容....

public class ZoomActivity extends Activity implements View.OnTouchListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_zoom);
    View v = findViewById(R.id.textv);
    v.setOnTouchListener(this);
}
    @Override
public boolean onTouch(View arg0, MotionEvent arg1) {
    CharSequence text="";
    switch(arg1.getAction()){
    case (MotionEvent.ACTION_POINTER_DOWN):
        text = "Pointer Down ";
        break;
    case (MotionEvent.ACTION_DOWN):
        text = "Down Action ";
        break;
    }
    if(arg1.getPointerCount()>1){
      text = text + "Multiple Presses "+arg1.getPointerCount();
    }
    else{
        text = text + "Single Press";
    }
    if(arg1.getHistorySize() > 0){
        text = text + " Previous x is "+arg1.getHistoricalAxisValue(MotionEvent.AXIS_X, 0);
    }
    else{
        text = text + " First press";
    }
    int duration = Toast.LENGTH_LONG;
    Toast toast = Toast.makeText(getApplicationContext(), text, duration);
    toast.show();
    return false;
}
}

问题是当我在我的设备上运行它时,getPointerCount 始终为 1。我在这里缺少什么?

4

1 回答 1

1

您从被覆盖的 onTouch 事件中返回 false,该事件将事件发送回未处理的链。你需要返回true,证明你自己处理过。:)

于 2013-07-12T13:49:14.637 回答