SwipeRefreshLayout嵌套ScrollView和RecyclerView

    xiaoxiao2021-03-25  89

    一、swiperefreshlayout嵌套scrollview和recyclerview设置(如果内容全部显示完毕,如不是分页加载)

      1、在activity中设置recyclerview禁止滑动

    LinearLayoutManager layoutManager = new LinearLayoutManager(mContext) { @Override public boolean canScrollVertically() { return false; } }; 2、xml中代码设置( SwipeRefreshLayout子元素只能有一个)

    <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/sign_detail_swiperefresh" android:layout_width="match_parent" android:layout_height="match_parent" > <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/sign_detail_recycleview" android:layout_width="match_parent" android:layout_height="match_parent" android:cacheColorHint="@null" android:scrollbars="vertical" /> </LinearLayout> </ScrollView> </android.support.v4.widget.SwipeRefreshLayout>

    3、如果不设置RecyclerView禁止滑动(一、1中内容)及设置xml中ScrollView变为NestedScrollView则分页加载可以实现但是滑动不流畅,原因是ScrollView和RecyclerView同时滑动冲突,此时在Activity中设置

    LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setSmoothScrollbarEnabled(true); layoutManager.setAutoMeasureEnabled(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setHasFixedSize(true); recyclerView.setNestedScrollingEnabled(false);此时设置recycleview禁止滑动后出现的问题是分页加载 到第二页时不显示加载内容啦。

    最后弄了半天时间也是醉啦,最后我的解决方案是不添加Scroll嵌套而是在adapter中想办法判断posion的位置,如果是-1的时候则加载头布局,这样滑动比较流畅

    转载请注明原文地址: https://ju.6miu.com/read-18822.html

    最新回复(0)