记录一个之前遇到的问题:
scrollView 嵌套recycleView 导致recycleView 复用失效问题
布局文件
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_scroll_inner"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="@android:color/white" />
</LinearLayout>
</androidx.core.widget.NestedScrollView
解决办法就是再代码中手动设置recycleView的固定高度;具体的高度根据自己的业务设置;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_scroll_view_test_layout1_converttest)
fillRecycleViewHeight()
recycle_view.adapter = adapter
recycle_view.layoutManager = LinearLayoutManager(this)
}
fun fillRecycleViewHeight() {
var recycleHeight = windowManager.defaultDisplay.height - recycle_view.top
recycle_view.layoutParams.height = recycleHeight
}