我需要一些幫助來處理列表視圖上的手勢。 我有,我希望能夠檢測到下面的佈局左側和右側刷卡的videoview:在ListView中不調用手勢OnFling
Link to a drawing of the current gesture and what is expected
,我用來捕捉事件的onFling方法不叫
public class OnSwipeTouchListener implements OnTouchListener {
private final GestureDetector gestureDetector;
private FeedAdapter callback;
public OnSwipeTouchListener(Context context, FeedAdapter callback) {
gestureDetector = new GestureDetector(context, new GestureListener());
this.callback = callback;
}
@Override
public boolean onTouch(final View view, final MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent);
}
private final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_THRESHOLD = 30;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
public boolean onSingleTapUp(MotionEvent e) {
Log.v("Tom", "tap");
triggerTouch();
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
boolean result = false;
Log.v("Swipe","is called"); // this is not called when swipe is not perfectly straight
try {
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > SWIPE_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}
public void onSwipeRight() {
}
public void onSwipeLeft() {
}
public void triggerTouch() {
}
public void onSwipeBottom() {
}
}
那麼如何讓用戶在略微偏離水平位置時調用onFling?
謝謝你的幫助!
湯米
這是行不通的,因爲世界上沒有super.onTouchEvent。我相信你的意思是 return super.onTouch(view,motionEvent); 但這也無法正常工作onTouchLisetener的onTouch是抽象的 http://developer.android.com/reference/android/view/View.OnTouchListener.html –