天天看點

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:兩種方法都親測有效。