解决RecyclerView条数显示不全问题

小知识解决大问题,问题处理+经验分享,大家好,我是时代新人!今天给大家分享一条小经验,请往下看:

多个RecyclerView同时使用的时候,比如线性垂直排布三个RecyclerView,那么会出现一个问题就是第一个RecyclerView的数据条数显示不全,只能显示一屏的内容,比如有10条数据,一屏只能显示5条,那么第一个RecyclerView就只显示5条数据,然后就显示下一个RecyclerView的数据了

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="visible">

        <!-- 第一部分 -->
        <RelativeLayout
            android:id="@+id/rl_theCaseMore"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dimen_40dp"
            android:paddingLeft="@dimen/dimen_14dp"
            android:paddingRight="@dimen/dimen_14dp"
            android:background="@color/gray_F7">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:textSize="@dimen/sp_14"
                android:textColor="@color/black"
                android:text="@string/the_case"/>
            <ImageView
                android:id="@+id/img_theCaseMore"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@mipmap/vibration_college_icon_more"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/img_theCaseMore"
                android:layout_marginRight="@dimen/dp_4"
                android:text="@string/more"
                android:textSize="@dimen/sp_12"
                android:textColor="@color/gray_7C"/>
        </RelativeLayout>
        <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_theBaseSearched"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="@dimen/dimen_14dp"
                android:paddingRight="@dimen/dimen_14dp"/>

        <!-- 第二部分 -->
        <RelativeLayout
            android:id="@+id/rl_productIntroductionMore"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dimen_40dp"
            android:paddingLeft="@dimen/dimen_14dp"
            android:paddingRight="@dimen/dimen_14dp"
            android:background="@color/gray_F7">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:textSize="@dimen/sp_14"
                android:textColor="@color/black"
                android:text="@string/product_introduction"/>
            <ImageView
                android:id="@+id/img_productIntroductionMore"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@mipmap/vibration_college_icon_more"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/img_productIntroductionMore"
                android:layout_marginRight="@dimen/dp_4"
                android:text="@string/more"
                android:textSize="@dimen/sp_12"
                android:textColor="@color/gray_7C"/>
        </RelativeLayout>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_productIntroductionSearched"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/dimen_14dp"
            android:paddingRight="@dimen/dimen_14dp"/>

        <!-- 第三部分 -->
        <RelativeLayout
            android:id="@+id/rl_vibrationBasedMore"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dimen_40dp"
            android:paddingLeft="@dimen/dimen_14dp"
            android:paddingRight="@dimen/dimen_14dp"
            android:background="@color/gray_F7">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:textSize="@dimen/sp_14"
                android:textColor="@color/black"
                android:text="@string/vibration_based"/>
            <ImageView
                android:id="@+id/img_vibrationBasedMore"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@mipmap/vibration_college_icon_more"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/img_vibrationBasedMore"
                android:layout_marginRight="@dimen/dp_4"
                android:text="@string/more"
                android:textSize="@dimen/sp_12"
                android:textColor="@color/gray_7C"/>
        </RelativeLayout>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_vibrationBasedSearched"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/dimen_14dp"
            android:paddingRight="@dimen/dimen_14dp"/>
    </LinearLayout>

</ScrollView>

解决办法,是给第一个RecyclerView的外层套一层线性布局就好了,像下面这样,只处理第一个RecyclerView就行,后面两个RecyclerView显示是正常的不用管。亲测有效,如果您有更好方法欢迎讨论

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_theBaseSearched"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="@dimen/dimen_14dp"
                android:paddingRight="@dimen/dimen_14dp"/>
        </RelativeLayout>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时代新人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值