android上拉加載更多顯示所有數據解決方法

本人在使用BaseQuickAdapter萬能適配器進行上拉加載更多數據時,運行時不管我滑動不滑動界面,下拉加載卻一直在加載更多數據,沒有達到我想要的下拉到最後開始加載更多數據的要求
廢話不多說,上佈局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/homeswipe"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <ScrollView android:layout_width="match_parent"
                android:layout_height="wrap_content"

    >
        <RelativeLayout
                android:descendantFocusability="blocksDescendants"
               
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    <com.youth.banner.Banner
            android:id="@+id/banner"
            android:layout_width="match_parent"
            android:layout_height="200dp" />


    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/home_recyc"
            android:layout_below="@+id/banner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

    </androidx.recyclerview.widget.RecyclerView>
        </RelativeLayout>
</ScrollView>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>

這裏就是我的界面佈局,scrollview嵌套輪播圖和recyclerview

導致問題的原因:

scrollview嵌套recyclerview進行上拉加載更多數據的時候 會一直走onCreateViewHolder()方法,scrollowview嵌套recyclerview,recyclerview會一次性把所有的數據進行加載 就導致現在的問題

解決方法:

我們可以利用BaseQuickAdapter提供的添加頭部 將banner定義到一個新的佈局中,這樣就可以不使用scrollview了 ,最簡單的就是你可以直接將scrollview刪除 不過這樣會導致界面不太美觀

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