data binding - How to change android RecyclerView child view height programatically? -
i want change recyclerview
items height programatically match_parent
or wrap_content
due size of content. how change height of child item?
divideritemdecoration divideritemdecoration = new divideritemdecoration(binding.rvoperation.getcontext(), divideritemdecoration.vertical); binding.rvoperation.setlayoutmanager(staggeredgridlayoutmanager); binding.rvoperation.additemdecoration(divideritemdecoration); log.d("countt", string.valueof(binding.rvoperation.getadapter().getitemcount()));
you need override onbindviewholder in recyclerview , call setlayoutparams on viewholder's container.
example:
@override public void onbindviewholder(simpleitemviewholder holder, int position){ // whatever here // add layout parameters here. here i'm setting width , height match parent tablerow.layoutparams params = new tablerow.layoutparams(tablerow.layoutparams.match_parent, tablerow.layoutparams.match_parent); //(width,height) holder.container.setlayoutparams(params); }
Comments
Post a Comment