如果targetSdkVersion = 23,RecyclerView的高度为wrap_content。那么列表会显示不完全,比如本来5条数据,只显示2条出来。如果如果targetSdkVersion = 22,会正常显示,不会有这个问题。
<ScrollView android:id="@+id/sv_credit" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:overScrollMode="never" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rvCreditPro" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="150dp" android:overScrollMode="never" android:scrollbars="vertical" /> </LinearLayout> </ScrollView>
解决办法如下:
在RecyclerView 外面套一层RelativeLayout就可以了。
<ScrollView android:id="@+id/sv_credit" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:overScrollMode="never" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <!--RelativeLayout 包裹在RecyclerView外面,是为了--> <!--解决targetSdkVersion >= 23 时的bug,否则ScrollView--> <!--嵌套RecyclerView ,会展示不完全。重写onMeasure也没用的。--> <android.support.v7.widget.RecyclerView android:id="@+id/rvCreditPro" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="150dp" android:overScrollMode="never" android:scrollbars="vertical" /> </RelativeLayout> </LinearLayout> </ScrollView>
当targetSdkVersion设置为23且RecyclerView高度为wrap_content时,在ScrollView内部可能会出现列表显示不全的情况。本文介绍了一种解决方案,即通过使用RelativeLayout包裹RecyclerView来避免这一问题。
2万+





