我正在尝试在我的偏好屏幕中添加手势,但我没有得到任何积极的结果,我的问题是我们可以向偏好屏幕添加手势吗?如果是,那么我如何使用下面的代码添加偏好的手势(不适用于偏好但它可以在两个 Activity 之间切换)
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return gestureDetector.onTouchEvent(event);
}
SimpleOnGestureListener simpleOnGestureListener
= new SimpleOnGestureListener(){
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
String swipe = "";
float sensitvity = 50;
// TODO Auto-generated method stub
if((e1.getX() - e2.getX()) > sensitvity){
// for left
Intent i=new Intent(getApplicationContext(),MyActivity.class);
startActivity(i);
finish();
}else if((e2.getX() - e1.getX()) > sensitvity){
//for right
}else{
swipe += "\n";
}
if((e1.getY() - e2.getY()) > sensitvity){
//Swipe Up
}else if((e2.getY() - e1.getY()) > sensitvity){
//Swipe Down
}
return super.onFling(e1, e2, velocityX, velocityY);
}
};
GestureDetector gestureDetector
= new GestureDetector(simpleOnGestureListener);