Layout - how to dynamically add views and interrupt a line based on empty space

I would like to have a Layout for Views on Android that controls itself to use its empty space dynamically, and ETAER adds the following view to the last view if it still fits OR breaks line and adds the view to a new line to the left ...

Example:

||Name|LoooooongName|Ho || ||SuperLongName|NextLongname || ||Bob|Sue|Martin|Richard|Joe || ||Marvin|Homer|Ann-Marie || 

Any clues? Thank you for your help!

+7
source share
1 answer

It is possible, but not easy. You will need to create your own layout. See the source code on LinearLayout for an example, specifically layoutHorizontal ().

You will override ViewGroup.onLayout (). In it, you will check the size of your children using View.getMeasured {Width, Height} (), making sure that they can fit in a row or move on to the next.

+1
source

All Articles