How to set RecyclerView Max Height

前端 未结 12 1630
陌清茗
陌清茗 2020-12-01 15:55

I want to set Max Height of RecylerView.I am able to set max height using below code.Below code makes height 60% of current screen.

     DisplayMetrics displ         


        
12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 16:12

    After trying way too many complicated suggestions, I finally figured this out through trial and error.

    First, wrap the RecyclerView in some sort of layout. In my case, I used a constraint layout, and I even had other elements in that layout above and below the RecyclerView. Set the height of the layout to auto adjust by setting it to 0dp, then set the default layout height constraint as wrap and define a layout max height constraint.

    Then, on your RecyclerView, set the height to wrap_content and layout_constrainedHeight to true.

    Here is what it should look like:

    
    
        
    
    
    

    Hope this helps!

提交回复
热议问题