RecyclerView inside ScrollView is not working

前端 未结 26 2256
梦如初夏
梦如初夏 2020-11-22 05:37

I\'m trying to implement a layout which contains RecyclerView and ScrollView at the same layout.

Layout template:


    

        
26条回答
  •  天命终不由人
    2020-11-22 06:29

    If you put RecyclerView inside NestedScrollView and enable recyclerView.setNestedScrollingEnabled(false);, scrolling will working well.
    However, there is a problem

    RecyclerView don't recycle

    For example, your RecyclerView (inside NestedScrollView or ScrollView) have 100 item.
    When Activity launch, 100 item will create (onCreateViewHolder and onBindViewHolder of 100 item will called at same time).
    Example, for each item, you will load a large image from API => activity created -> 100 image will load.
    It make starting Activity slowness and lagging.
    Possible solution:
    - Thinking about using RecyclerView with multiple type.

    However, if in your case, there are just a few item in RecyclerView and recycle or don't recycle don't affect performance a lot, you can use RecyclerView inside ScrollView for simple

提交回复
热议问题