1

We have horizontal recycler view. Each item view of recycler view contains a textView. Width of each item view is constant, 100dp. Height is dynamic & we have to set it as per the max data. List of string is coming from server & hence any data can come. So, e.g. 1st cell can have text of 1 line whereas 2nd cell can have text of 4 lines.

Requirement: We have to calculate maximum height of the cell (i.e cell consuming max height due to biggest text) and set that maximum height to all cells of recycler view. This is required because we want height of all item views to be same & also making biggest text visible to user without getting cut (ellipse).

One of the ways that I know: Before setting adapter, we can iterate the list containing Strings. We can create a dummy textview (invisible to user & width 100 dp). We can set each of the text in the textview & then get height of the textview. We will save the maximum height to adapter while calling setAdapter.

Is this good approach? Please help.

  • I found 2 relevant links for you https://stackoverflow.com/questions/51325075/horizontal-recyclerview-follows-first-item-height-with-wrap-content. https://github.com/thoughtbot/expandable-recycler-view/issues/53 – akashzincle Apr 16 '20 at 19:57
  • Thanks @akashzincle but I was trying to keep recycler view height as wrap_content, setting textview height programatically (setting all textviews height as max height of the string). Reason for this is recycler view can have multiple components (say textviews + imageviews). Simply keeping recycler view height as wrap_content & setting height in all textviews same can make things great. – Robin Sharma Apr 17 '20 at 07:20

0 Answers0