2

I am getting started with Android, trying to write a "concentration" game for kids where a screen full of text is separated into buttons, filling the screen (one word per button)

The buttons should wrap to the contained text, so longer words will have longer button widths.

Once a row fills up, the next button should flow to the next row, and so on, until the whole screen is filled with evenly spaced variable width buttons.

The number of rows and number of buttons per row varies based on screen size (and as mentioned, button width)

I could use a vertical linear layout, then insert horizontal linear layouts to contain the row text. However I don't see how to make those widths and number of rows vary based on the screen size and text size.

I presume I need to create my own custom layout, something like FlowLayout in Spring - if so, can you recommend a tutorial for how to do so?

Victor Grazi
  • 15,563
  • 14
  • 61
  • 94
  • The latest seems to be [Flow](https://developer.android.com/reference/androidx/constraintlayout/helper/widget/Flow) but I'm not sure yet if it handles variable width widgets (so longer words have longer button widths). But for that requirement, I've seen it for [flexbox-layout](https://github.com/google/flexbox-layout#supported-attributes) and [Dhaval Solanki's FlowLayout](https://stackoverflow.com/a/41013282/2848676) – Michael Osofsky Aug 17 '19 at 01:06
  • I've just posted a new question to find out if Flow can do it, https://stackoverflow.com/questions/57532591/can-the-android-flow-virtual-layout-handle-variable-width-views – Michael Osofsky Aug 17 '19 at 01:12

1 Answers1

0

Check android's API Demos

  • Animation->DefaultLayoutAnimation (for example)

  • LayoutAnimationsByDefault.java & layout_animations_by_default.xml (for source)

It uses GridLayout and with a bit of modifications of mentioned example, it will be useful for your case..It's flexible, it's available since API Level 14, but it's available trought support/compatibility library or 3rd party library .

Hope this will help.. Cheers ;)

Ewoks
  • 12,285
  • 8
  • 58
  • 67