天天看點

android 記錄RecyclerView和ScrollView滑動沖突的BUG

 一、RecyclerView和ScrollView滑動沖突的BUG,缺點onBindViewHolder時會把清單中的全部資料加載出來,有點難受。不知道有沒有其他解決方法。

mWifiRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()){
    @Override
    public boolean canScrollVertically() {
        return false;//修複wifi清單滑動卡頓,RecyclerView和ScrollView沖突的bug
    }
    @Override
    public boolean canScrollHorizontally() {
        return false;//水準的話重寫這個方法
    }
});
           

二、另外加一個BUG是為了禁止recyclerview下滑,有點雞肋,特定場景使用到了。

//禁止recyclerview下滑
public class MyGridLayoutManager extends GridLayoutManager {

    private boolean isScrollEnabled = true;

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

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

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


}
           
MyGridLayoutManager myGridLayoutManager = new MyGridLayoutManager(this,3);
myGridLayoutManager.setOrientation(RecyclerView.VERTICAL);
myGridLayoutManager.setScrollEnabled(false);
mRightRecyclerView.setLayoutManager(myGridLayoutManager);