Recycler View loading very slow for large data when inside NestedScrollView

后端 未结 3 1529
执笔经年
执笔经年 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
    
    0 讨论(0)
  • 2021-02-05 21:08

    This case of RecyclerView inside NestedScrollView.

    RecyclerView is calling onCreateViewHolder() times equal to your data size.

    If data has 200 items, it freezes for onCreateViewHolder() to be called 200 times.

    0 讨论(0)
  • 2021-02-05 21:18

    As said by Nancy , recyclerview.setNestedScrollingEnabled(false); will solve scroll stuck issue. i too faced this type of issue and solved by false the NestedScroll.

    0 讨论(0)
提交回复
热议问题