Scrollview 嵌套 RecyclerView 显示不全

为何显示不全

对 Recyclerview 的布局的测量不准确

在自己项目中的表现

自己通过 Debug 发现,传进 adapter 的 list 的size 为10 ,但是在进行显示数据的时 position 在经历了 0 、1 、2 后 ,该过程停止,数据停止了继续显示。而此时数据显示的高度正好为手机屏幕的高度大一些,表现为微小的滑动。

怎样显示全部

解决方案:

1. ScrollView --> NestedScrollView (NestedScrollView 解决了内部滑动冲突)

<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 的宽高 (但是自己使用并没有见效)

具体的方案可以在网上随便搜,到处都是。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容