Home > Software engineering >  Creating a custom layout for horizontal buttons with wrapping
Creating a custom layout for horizontal buttons with wrapping

Time:04-18

I wasn't sure what to title this without explaining it all there. Essentially, I want to populate part of a screen with a bunch of buttons. The buttons should have text from an ArrayList (or other structure) and they should be aligned horizontally to each other from the left to the right of the screen. When there is no more room to the right, it starts a new row. I've attached an example. Example layout here

I know how to make custom list adapters for my objects and how to make listeners for parts within the list items, but I'm just not sure how to make the "list" of buttons go horizontally with wrapping to the next line.

CodePudding user response:

It seems https://github.com/google/flexbox-layout might help you.

You can use FlexboxLayoutManager as adapter, or simply place all the buttons inside FlexboxLayout, they will wrap automatically depending on their width.

  • Related