我已经制作Gesture
了从左到右和从右到左使用滑动检测的应用程序。
我在 2.2 AVD 模拟器上取得了成功,但是当我尝试在平板电脑 3.0 中使用相同的代码时它不起作用
请告诉我有什么问题。
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private class GestureListener extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(RssActivity.this, "Right to left",
Toast.LENGTH_LONG).show();
SetNewRightclickActivity();
Log.i(TAG, "Right to left");
return true; // Right to left
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(RssActivity.this, "Left to right",
Toast.LENGTH_LONG).show();
Log.i(TAG, "Left to right");
SetNewLeftclickActivity();
return true; // Left to right
}
if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
return true; // Bottom to top
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
return true; // Top to bottom
}
return false;
}
}
主要的::
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rssheader);
gestureDetector = new GestureDetector(new GestureListener());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};