使用divider解决RecyclerView内容显示不全的问题

本文探讨了RecyclerView在特定布局下内容显示不全的问题,并提出了解决方案。通过自定义IdeaScrollView包裹LinearLayout,其中包含RecyclerView和divider,解决了RecyclerView默认不计算上方控件高度导致的内容显示不全问题。
使用第三方自定义IdeaScrollView包裹一个LinearLayout,LinearLayout中包裹RecyclerView和divider,divider宽度固定取到RecyclerView的内容显示完整为止

<com.test.view.IdeaScrollView
    android:id="@+id/ideaScrollView_category_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView10">

    <LinearLayout
        android:id="@+id/ll_root02"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_category_list_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">

        </android.support.v7.widget.RecyclerView>

        <View
            android:id="@+id/divider18"
            android:layout_width="match_parent"
            android:layout_height="170dp"
            android:background="@color/foreground"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/recyclerView_category_list_content" />

    </LinearLayout>

</com.test.view.IdeaScrollView>

 

内容显示不全的根本原因应该就是RecyclerView在计算布局所使用的高度偏移量时默认没有计算位于RecyclerView上方的控件的高度,所以解决问题的根本方法应该是自定义一个RecyclerView继承android.support.v7.widget.RecyclerView,重写onmeasure(),在计算RecyclerView高度时算上上方控件所占高度(过程,代码往后补)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值