向左滑动以刷新horizo​​ntall recyclerView

时间:2016-08-17 12:55:41

标签: android android-recyclerview

我想在我的应用中实现此功能。

问题是,所有swipeRefreshLayouts仅用于下拉手势。

我想在我的recyclerView中向左/向右滑动,当我达到最大值时,然后滑动布局并在swipeRefreshLayout中显示刷新。

有可能吗?

1 个答案:

答案 0 :(得分:0)

public class CustomSwipeToRefresh extends SwipeRefreshLayout {

    private int mTouchSlop;
    private float mPrevX;

    public CustomSwipeToRefresh(Context context, AttributeSet attrs) {
        super(context, attrs);

        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mPrevX = MotionEvent.obtain(event).getX();
                break;

            case MotionEvent.ACTION_MOVE:
                final float eventX = event.getX();
                float xDiff = Math.abs(eventX - mPrevX);

                if (xDiff > mTouchSlop) {
                    return false;
                }
        }

        return super.onInterceptTouchEvent(event);
    }
}

使用 CustomSwipeToRefresh 代替 SwipeRefreshLayout