我正在开发 Android ListView。我通过 XListView 实现了下拉刷新,但现在我还想实现从左向右滑动以在这个 ListView 上显示按钮列表项。我该怎么做?或者如何在 ListView 上添加 2 个相同的库。
我的 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" />
最佳答案
@覆盖 公共(public) bool onInterceptTouchEvent(MotionEvent ev){ int action = MotionEventCompat.getActionMasked(ev); 最终 float x = ev.getX(); 最终 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;
}
}
关于Android ListView 拉动刷新和滑动列表项以显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30187291/