Scrollview 嵌套 RecyclerView 顯示不全

為何顯示不全

對 Recyclerview 的布局的測量不準(zhǔn)確

在自己項(xiàng)目中的表現(xiàn)

自己通過 Debug 發(fā)現(xiàn),傳進(jìn) adapter 的 list 的size 為10 ,但是在進(jìn)行顯示數(shù)據(jù)的時 position 在經(jīng)歷了 0 、1 、2 后 ,該過程停止,數(shù)據(jù)停止了繼續(xù)顯示。而此時數(shù)據(jù)顯示的高度正好為手機(jī)屏幕的高度大一些,表現(xiàn)為微小的滑動。

怎樣顯示全部

解決方案:

1. ScrollView --> NestedScrollView (NestedScrollView 解決了內(nèi)部滑動沖突)

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:scrollbars="none">

            <android.support.v7.widget.RecyclerView
                    android:id="@+id/rv_edit_menu_total"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

  </android.support.v4.widget.NestedScrollView> 
2. RecyclerView 外部嵌套 RelativeLayout 或 LinearLayout
<RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:descendantFocusability="blocksDescendants">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rv_edit_menu_total"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

</RelativeLayout>
3. 重寫 RecyclerView 的 LinearLayoutManager 或 GridLayoutManager 去測量 RecyclerView 的寬高 (但是自己使用并沒有見效)

具體的方案可以在網(wǎng)上隨便搜,到處都是。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容