0

I want to display a set amount of lines of buttons in view. I have no clear limit in how many buttons I want to add. It just should show on X lines in the UI.

I used a Constraint layout with a Flow helper which allow me to display the buttons side by side in several lines. However the Constraint layout and Flow do not have a notion of "max lines".

To solve this I tried to display all the button, collect all their Y positions to identify which one are on lines after line X, and remove them. This led me to add listeners to the layout but none of them allowed me to fix my concern.

  • View.AddOnLayoutChangeListener: I succeed to remove the view that were on line > X. But the containing constraintlayout would still use the space that was necessary to fit all the button. I wish the constraintlayout would reduce and use only the size for X lines to fit in it. It also would start some sort of infinite loop as I would edit the layout after some layout.
  • viewTreeObserver.addOnPreDrawListener: Removing the view in them, and returning false in it make the constraintlayout have a height of 0, and all the buttons aren't well positioned.
Pol
  • 482
  • 3
  • 11

0 Answers0