Android ListView拉动刷新和滑动列表项以显示按钮

use*_*456 2 android android-listview swipe-gesture pull-to-refresh

我正在使用Android ListView.我通过XListView实现了pull刷新,但现在我还想实现从左向右滑动以在此ListView上显示按钮List Item.我该怎么做?或者如何在ListView上添加2个libs.

我在XML中的ListView是.

<com.orderlyexpo.www.listview.refresh.XListView
        android:id="@+id/lvOrders"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@color/gray_text"
        android:dividerHeight="@dimen/dp1x" /> 
Run Code Online (Sandbox Code Playgroud)

小智 5

@Override public boolean onInterceptTouchEvent(MotionEvent ev){int action = MotionEventCompat.getActionMasked(ev); final float x = ev.getX(); final float y = ev.getY();

    if (isEnabled() && touchListener.isSwipeEnabled()) {

        if (touchState == TOUCH_STATE_SCROLLING_X) {
            return touchListener.onTouch(this, ev);
        }

        switch (action) {
            case MotionEvent.ACTION_MOVE:
                checkInMoving(x, y);
                return touchState == TOUCH_STATE_SCROLLING_Y;
            case MotionEvent.ACTION_DOWN:
                super.onInterceptTouchEvent(ev);
                touchListener.onTouch(this, ev);
                touchState = TOUCH_STATE_REST;
                lastMotionX = x;
                lastMotionY = y;
                return false;
            case MotionEvent.ACTION_CANCEL:
                touchState = TOUCH_STATE_REST;
                break;
            case MotionEvent.ACTION_UP:
                touchListener.onTouch(this, ev);
                return touchState == TOUCH_STATE_SCROLLING_Y;
            default:
                break;
        }
    }

    return super.onInterceptTouchEvent(ev);
}

/**
 * Check if the user is moving the cell
 *
 * @param x Position X
 * @param y Position Y
 */
private void checkInMoving(float x, float y) {
    final int xDiff = (int) Math.abs(x - lastMotionX);
    final int yDiff = (int) Math.abs(y - lastMotionY);

    final int touchSlop = this.touchSlop;
    boolean xMoved = xDiff > touchSlop;
    boolean yMoved = yDiff > touchSlop;

    if (xMoved) {
        touchState = TOUCH_STATE_SCROLLING_X;
        lastMotionX = x;
        lastMotionY = y;
    }

    if (yMoved) {
        touchState = TOUCH_STATE_SCROLLING_Y;
        lastMotionX = x;
        lastMotionY = y;
    }
}
Run Code Online (Sandbox Code Playgroud)

使用此库