Recycler View loading very slow for large data when inside NestedScrollView

后端 未结 3 1537
执笔经年
执笔经年 2021-02-05 20:45

I have added RecyclerView inside my NestedScrollView. Basically I want RecyclerView to scroll with other Views. The problem that I am facing is that fo

3条回答
  •  一个人的身影
    2021-02-05 21:02

    The problem as said above is because RecyclerView as a child or subChild in NestedScrollView measures its height as infinitive when you use WRAP_CONTENT or MATCH_PARENT for height of RecyclerView.

    one solution that solved this problem for me was setting the RecyclerView Height to a fixed size. you could set height to a dp value, or you could set it to a pixel value matching devices height if your requirements needs a vertical infinitive RecyclerView.

    here is a snippet for setting the recyclerView size in kotlin

        val params = recyclerView.layoutParams
        params.apply {
                width = context.resources.displayMetrics.widthPixels
                height = context.resources.displayMetrics.heightPixels
        }
        recyclerView.layoutParams = params
    

提交回复
热议问题