Recyclerview嵌套recyclerview滑动冲突解决(多指方案)
程序员文章站
2024-03-24 15:13:40
...
public class QRecyclerView extends RecyclerView {
private int mStartX = 0;
private int mStartY = 0;
private int mTouchSlop = 0;
private int mScrollPointerId = -1;
public QRecyclerView(@NonNull Context context) {
super(context);
}
public QRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction();
final int actionIndex = ev.getActionIndex();
switch (action) {
case MotionEvent.ACTION_DOWN:
mScrollPointerId = ev.getPointerId(0);
mStartX = (int) (ev.getX() + 0.5f);
mStartY = (int) (ev.getY() + 0.5f);
break;
case MotionEvent.ACTION_POINTER_DOWN:
mScrollPointerId = ev.getPointerId(actionIndex);
mStartX = (int) (ev.getX(actionIndex) + 0.5f);
mStartY = (int) (ev.getY(actionIndex) + 0.5f);
break;
case MotionEvent.ACTION_MOVE:
final int index = ev.findPointerIndex(mScrollPointerId);
final int x = (int) (ev.getX(index) + 0.5f);
final int y = (int) (ev.getY(index) + 0.5f);
float distanceX = Math.abs(x - mStartX);
float distanceY = Math.abs(y - mStartY);
if (distanceX > mTouchSlop && distanceX > distanceY) {
return false;
}
break;
case MotionEvent.ACTION_POINTER_UP:
onPointerUp(ev);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return super.onInterceptTouchEvent(ev);
}
private void onPointerUp(MotionEvent e) {
final int actionIndex = e.getActionIndex();
if (e.getPointerId(actionIndex) == mScrollPointerId) {
// Pick a new pointer to pick up the slack.
final int newIndex = actionIndex == 0 ? 1 : 0;
mScrollPointerId = e.getPointerId(newIndex);
mStartX = (int) (e.getX(newIndex) + 0.5f);
mStartY = (int) (e.getY(newIndex) + 0.5f);
}
}
推荐阅读
-
Recyclerview嵌套recyclerview滑动冲突解决(多指方案)
-
Android中RecyclerView嵌套滑动冲突解决的代码片段
-
Android中RecyclerView嵌套滑动冲突解决的代码片段
-
Android RecyclerView多类型布局卡片解决方案
-
RecyclerView嵌套RecyclerView滑动卡顿的解决方法
-
ScrollView(RecyclerView等)为什么会自动滚动原理分析,还有阻止自动滑动的解决方案
-
BottomSheetBehavior+ViewPager+RecyclerView引起的滑动冲突事件解决
-
使用RecyclerView解决滑动冲突(RecyclerView添加header)
-
解决Scrollview和ExpandableListView/ListView/Recyclerview 之间的滑动冲突
-
解决swipeRefreshLayout与RecyclerView的滑动冲突