所以我在相对布局中有两个叠加视图。要求是在长按第一个视图后调用第二个视图的触摸事件(以应用手势)。 真的搞砸了触摸和点击事件。如果有人能提供更好的解决方案。
这是我的代码:
gestureDetector = new GestureDetector(this, new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
MainActivity.this.event= event;
return gestureDetector.onTouchEvent(event);
}
};
gestureDetector.setIsLongpressEnabled(false);
above = (Button) findViewById(R.id.above);
above.setOnTouchListener(gestureListener);
below = (Button) findViewById(R.id.below);
below.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.d("long", "click");
//call on down of above here and set visibility gone of below
return true;
}
});
我也尝试过dispatchtouchevent(事件);但是哪个事件必须从这里发出?
MyGestureDetector类是:
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
Log.e("action", "down");
//for applying scroll gestures onto it
return true;
}
}