美文网首页
Scrollview 嵌套 RecyclerView 显示不全

Scrollview 嵌套 RecyclerView 显示不全

作者: GYLEE | 来源:发表于2017-10-13 13:29 被阅读1044次

    为何显示不全

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

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

    相关文章

      网友评论

          本文标题:Scrollview 嵌套 RecyclerView 显示不全

          本文链接:https://www.haomeiwen.com/subject/icmoyxtx.html