為何顯示不全
對 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)上隨便搜,到處都是。