Layout - How to dynamically add views and break line based on empty space
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.
精彩评论