Android - how to change Recyclerview height dynamically?

前端 未结 5 787
天涯浪人
天涯浪人 2020-12-28 16:36

I\'m stuck with an issue about changing Recycler height based on its total items. What I have tried is to use Layout Param like this:

        ViewGroup.Layo         


        
5条回答
  •  执念已碎
    2020-12-28 17:42

    You should use LayoutParams of parent's view in setLayoutParams(params).

    For example:

    
        
        
     
    

    Change LayoutParams in the code.

      RelativeLayout.LayoutParams lp =
                new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 500);
     recyclerView.setLayoutParams(lp);
    

提交回复
热议问题