美文网首页
scrollView 嵌套recycleView复用失效的解决办

scrollView 嵌套recycleView复用失效的解决办

作者: 奔波儿灞_q | 来源:发表于2020-06-22 17:34 被阅读0次

记录一个之前遇到的问题:
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
    }

相关文章

网友评论

      本文标题:scrollView 嵌套recycleView复用失效的解决办

      本文链接:https://www.haomeiwen.com/subject/fgcffktx.html