特别说明:
对于NestedScrollView嵌套RecylcerView不建议在数据量很大的情况下使用,因为这种嵌套会导致RecyclerView的item被展开,导致复用失效。
在使用NestedScrollView + RecyclerView 嵌套的时候,会出现卡顿情况,大致布局如下,在网上找了处理方式,在此记录下
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tvSpace">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/forward_banner_layout" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvContentList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false" /> //在api21之后生效,可以确保api21+的不会卡顿
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
对于老版本手机(api21-),处理方式如下
val layoutManager = LinearLayoutManager(this)
layoutManager.isSmoothScrollbarEnabled = true
layoutManager.isAutoMeasureEnabled = true
rvContentList.layoutManager = layoutManager
rvContentList.setHasFixedSize(true)
rvContentList.isNestedScrollingEnabled = false
rvContentList.adapter = mAdapter