开发者

Layout - How to dynamically add views and break line based on empty space

开发者 https://www.devze.com 2023-02-13 23:33 出处:网络
I would like to have a Layout for Views in Android that manages itself to use its empty space dynamically and EITHER puts the next view added right to the last view if it still fits O开发者_JAVA百科R

I would like to have a Layout for Views in Android that manages itself to use its empty space dynamically and EITHER puts the next view added right to the last view if it still fits O开发者_JAVA百科R breaks line and adds the view on the new line on the left...

Example:

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

Any clues? Thanks for your help!


This is possible, but not easy. You will have to create a custom layout. Check out the source code to LinearLayout for an example, specifically layoutHorizontal().

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

0

精彩评论

暂无评论...
验证码 换一张
取 消