2023年7月15日发(作者:)
NestedScrollView嵌套RecycleView滑动冲突解决办法解决办法:1.简单的⽅法⾸先把design库和V7库升级到23.2以上,然后添加如下代码othScrollbarEnabled(true);oMeasureEnabled(true);outManager(linearLayoutManager);FixedSize(true);tedScrollingEnabled(false);经验证好⽤。。。2.⽐较⿇烦的,重写LinearLayoutManager和NestedScrollViewpublic class CustomLinearLayoutManager extends LinearLayoutManager {
public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
private int[] mMeasuredDimension = new int[2];
@Override
public void onMeasure(er recycler, state,
int widthSpec, int heightSpec) {
final int widthMode = e(widthSpec);
final int heightMode = e(heightSpec);
final int widthSize = e(widthSpec);
final int heightSize = e(heightSpec);
int width = 0;
int height = 0;
for (int i = 0; i < getItemCount(); i++) {
if (getOrientation() == HORIZONTAL) {
measureScrapChild(recycler, i,
asureSpec(i, IFIED),
heightSpec,
mMeasuredDimension);
width = width + mMeasuredDimension[0];
if (i == 0) {
height = mMeasuredDimension[1];
}
} else {
measureScrapChild(recycler, i,
widthSpec,
asureSpec(i, IFIED),
mMeasuredDimension);
height = height + mMeasuredDimension[1];
if (i == 0) {
width = mMeasuredDimension[0];
}
}
}
switch (widthMode) {
case Y:
width = widthSize;
case _MOST:
case IFIED:
} }
switch (heightMode) {
case Y:
height = heightSize;
case _MOST:
case IFIED:
}
setMeasuredDimension(width, height);
}
private void measureScrapChild(er recycler, int position, int widthSpec,
int heightSpec, int[] measuredDimension) {
View view = wForPosition(position);
ewToPosition(view, position);
if (view != null) {
Params p = (Params) outParams();
int childWidthSpec = ldMeasureSpec(widthSpec,
getPaddingLeft() + getPaddingRight(), );
int childHeightSpec = ldMeasureSpec(heightSpec,
getPaddingTop() + getPaddingBottom(), );
e(childWidthSpec, childHeightSpec);
measuredDimension[0] = suredWidth() + rgin + argin;
measuredDimension[1] = suredHeight() + Margin + gin;
eView(view);
}
}
}
public class MyNestedScrollView extends NestedScrollView {
private int downX;
private int downY;
private int mTouchSlop;
public MyNestedScrollView(Context context) {
super(context);
mTouchSlop = (context).getScaledTouchSlop();
}
public MyNestedScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mTouchSlop = (context).getScaledTouchSlop();
}
public MyNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mTouchSlop = (context).getScaledTouchSlop();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
int action = ion();
switch (action) {
case _DOWN:
downX = (int) X();
downY = (int) Y();
break;
case _MOVE:
int moveY = (int) Y();
if ((moveY - downY) > mTouchSlop) {
return true;
}
}
return rceptTouchEvent(e);
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/web/1689429223a246762.html
评论列表(0条)