Android6.0 ScrollView跟两个垂直RecyclerView冲突处理

1,先解决第一个recyclerview不能完整显示的问题

在俩个recyclerview外面都包裹一个相对布局RelativeLayout,一定是俩个recyclerview都要包裹。我试着只包裹下底部的一个,发现当底部的数据增多时,会出现异常。

2,当第二个recyclerview部分超出屏幕时,滑动时只有recyclerView,scrollview不会动

原因还是滑动冲突的问题,我的解决方案是,重写LinearLayoutManager,设置让其不可滑动,外部滑动靠ScrollView

public class ScrollGridLayoutManager extends GridLayoutManager{

    private boolean isScrollEnabled = true;
    
    public ScrollGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public ScrollGridLayoutManager(Context context, int spanCount) {
        super(context, spanCount);
    }

    public ScrollGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
        super(context, spanCount, orientation, reverseLayout);
    }

    @Override
    public boolean canScrollVertically() {
        return super.canScrollVertically() && isScrollEnabled;
    }

    public void setScrollEnabled(boolean flag) {
        this.isScrollEnabled = flag;
    }
}





猜你喜欢

转载自blog.csdn.net/xiadanxin/article/details/74841986