我正在尝试使用SwipeCards库使匹配屏幕像Tinder一样。我在卡适配器中有一个viewpager。我想在单击不可见视图时显示用户的下一张照片。为了这;我为不可见的视图实现了GestureListener,并且检测到触摸事件是滑动或单击。如果事件已滑动;那么SwipeCard onTouch必须触发。但是此逻辑不起作用,我无法切换onTouch状态,也无法弄清楚如何解决此问题。
这是我的CustomGestureListener:
no_emails, no_phone_numbers
我正在这样的片段中使用此侦听器:
public abstract class CustomGestureListener extends GestureDetector.SimpleOnGestureListener {
private final View mView;
public CustomGestureListener(View view){
mView = view;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
mView.onTouchEvent(e);
return super.onSingleTapConfirmed(e);
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
onTouch();
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e1.getX() < e2.getX()) {
return onSwipeRight();
}
if (e1.getX() > e2.getX()) {
return onSwipeLeft();
}
return onTouch();
}
public abstract boolean onSwipeRight();
public abstract boolean onSwipeLeft();
public abstract boolean onTouch();
}
这是我的xml:
mGestureDetector = new GestureDetector(getActivity(), new CustomGestureListener(viewRightNavigation) {
@Override
public boolean onSwipeRight() {
//
return false;
}
@Override
public boolean onSwipeLeft() {
//
return true;
}
@Override
public boolean onTouch() {
return false;
}
});
viewRightNavigation.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return !mGestureDetector.onTouchEvent(event);
}
});
viewRightNavigation.setGestureDetector(mGestureDetector);