1

I'm trying to achieve something similar to this:

widget demo

So, this is a container which can hold an arbitrary number of children. Each child is a simple text with border. Children may differ by their width. I assume this part can be implemented by extending the TextView widget (since it isn't clickable). Much more interesting thing here is the container for these bordered text views. It should support a regular addView(child) operation which automatically aligns the child according to the simple rule: if there is enough room within a current row - place child to the right of the last item in row. If there is no space - move child to the next row. So the basic logic seems quite similar to TextView or EditText: if text is too long, we display it in several lines. My idea is too extend RelativeLayout, but I still hope to find something easier.

The scheme I've described above (custom container + custom TextView) is not a mandatory, I'm just looking for ways to achieve this. Any thoughts guys?

fraggjkee
  • 3,524
  • 2
  • 32
  • 38
  • button with custom style? Android will manage the most of things for you, and you just need to edit the background – Marco Acierno May 31 '14 at 17:30
  • I'm looking mostly for a way to implement a dynamic container. Sure, it's not a problem to customize a background, but I need to dynamically add several views (into single parent `ViewGroup`) and they should be properly aligned. – fraggjkee May 31 '14 at 17:34
  • 1
    It seems to me you're describing a FlowLayout. A bit old but should be goold enough: http://stackoverflow.com/questions/4474237/how-can-i-do-something-like-a-flowlayout-in-android – nitzanj May 31 '14 at 18:00

1 Answers1

0

Seems that pattern I was looking for is called FlowLayout (thanks to nitzanj). There are several of implementations of it:

If you decide to write your own version, here are helpful guides about writing custom views:

Community
  • 1
  • 1
fraggjkee
  • 3,524
  • 2
  • 32
  • 38