在新版本中需求变更导致布局需要变化,RecyclerView外需要一层ScrollView来处理滑动。发布前夕发现在API 23 & 24上RecyclerView显示不完整。
光速冷静下来,马上去stackoverflow翻了一下,有人说ScrollView加上 android:fillViewport="true"
,但是我加上并没有解决问题。后来在RecyclerView外面加了一层RelativeLayout,问题解决。如果你在API 23 & 24上也遇到这个问题,可以参考一下。
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- DEV NOTE: Outer wrapper relative layout is added intentionally to address issue
that only happens on Marshmallow & Nougat devices (API 23 & 24).
On marshmallow API 23, the "RecyclerView" `layout_height="wrap_content"` does NOT
occupy the height of all the elements added to it via adapter. The result is cut out
items that is outside of device viewport when it loads initially.
Wrapping "RecyclerView" with "RelativeLayout" fixes the issue on Marshmallow devices.
-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="@+id/rv_fragment_find_tips_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>