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;
    }
}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章