天天看点

ScrollView与RecyclerView嵌套使用,导致adapter显示不全

ScrollView与RecyclerView嵌套使用,导致adapter的item显示不全

直接进入正题

我们在项目中,经常性遇到ScrollView与RecyclerView嵌套使用的场景,结果我们在满怀信心的做出来后,一演示竟然发现我们adapter的item怎么会没有显示全呢。这里提供两种方法。

方法一

直接把ScrollView的地方修改成NestedScrollView。如下:

<android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
 <android.support.v7.widget.RecyclerView
                    android:id="@+id/rlv_miaofa"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    />
 </android.support.v4.widget.NestedScrollView>
           
方法二

在RecyclerView的外面再套一层RelativeLayout即可,示例如下:

<RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
     <android.support.v7.widget.RecyclerView
         android:id="@+id/rlv_miaofa"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/>
</RelativeLayout>
           

ps:两种方法都亲测有效。