android listview - onfling不一致

时间:2015-11-18 15:16:55

标签: android listview gesturedetector onfling

根据Android: How to handle right to left swipe gestures中的代码,我为GestureDetector创建了以下ListView以处理滑动。

    public ListEntryViewHolder(View view) {
        ButterKnife.bind(this, view);
        mGestureDetector = new GestureDetector(view.getContext(), new ListSwipeListener(view));
    }

    @OnTouch(R.id.rl_list_entry)
    boolean ListTouch(View ListEntry, MotionEvent event) {
        mGestureDetector.onTouchEvent(event);
        return false;
    }

摘要GestureDetector看起来像

public abstract class LeftRightSwipeListener extends SimpleOnGestureListener {

    private static final int SWIPE_DISTANCE_THRESHOLD = 5;
    private static final int SWIPE_VELOCITY_THRESHOLD = 5;

    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        // Print Statement
        // Swipe Based Code that does some math and calls onSwipeRight() and onSwipeLeft()
    }

    public abstract void onSwipeRight();
    public abstract void onSwipeLeft();
}

使用print中的OnFling语句,我发现onFling以非常不一致的方式被调用;只有大约一半的滑动触发了要调用的功能。如果在调用该函数时,它能够区分onSwipeRight()onSwipeLeft()就好了。禁用长时间点击似乎有点帮助,但不清楚为什么onFling只会不时触发,也许MotionEvents会被某个地方消耗掉?

0 个答案:

没有答案