RecyclerView inside ScrollView is not working

前端 未结 26 2187
梦如初夏
梦如初夏 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:09

    I know I am late it the game, but the issue still exists even after google has made fix on the android.support.v7.widget.RecyclerView

    The issue I get now is RecyclerView with layout_height=wrap_content not taking height of all the items issue inside ScrollView that only happens on Marshmallow and Nougat+ (API 23, 24, 25) versions.
    (UPDATE: Replacing ScrollView with android.support.v4.widget.NestedScrollView works on all versions. I somehow missed testing accepted solution. Added this in my github project as demo.)

    After trying different things, I have found workaround that fixes this issue.

    Here is my layout structure in a nutshell:

    
       (vertical - this is the only child of scrollview)
         
          (layout_height=wrap_content)
         
    

    The workaround is the wrap the RecyclerView with RelativeLayout. Don't ask me how I found this workaround!!! ¯\_(ツ)_/¯

    
    
        
    
    
    

    Complete example is available on GitHub project - https://github.com/amardeshbd/android-recycler-view-wrap-content

    Here is a demo screencast showing the fix in action:

    Screencast

提交回复
热议问题