版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wanggang514260663/article/details/89887423
在使用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