项目开发中使用
CoordinatorLayout,在
AppBarLayout中嵌套使用RecycleView,但是发现RecycleView滑动向上滑动时,会触发
AppBarLayout的上滑,导致RecycleView只能下滑但无法上滑,解决办法是重写RecyclerView
public class MyRecycleView extends RecyclerView {
public MyRecycleView(Context context) {
super(context);
}
public MyRecycleView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyRecycleView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent e) {
stopNestedScroll();
return super.onTouchEvent(e);
}
}
stopNestedScroll();告诉父布局滚动结束
所以只要在滑动中高度父控件滑动结束了 则RecycleView 就能自由的飞翔啦! |