Ok, my problem is, I have got n-TextViews and they will be added programmatically into a TableLayout. It totally doesnt matter, how I style these TextViews or the TableLayout, everytime I add something, it adds the TextView on the bottom after the other TextViews.
These Views have got a variable width, which is calculated out of their textlength and some pixels (WRAP_CONTENT just made 100% width…).
It is like this right now:
------------------------------------------
[TextView 1]
[TextView 2]
[TextView 3]
[TextView 4]
------------------------------------------
And it should be like:
------------------------------------------
[TextView 1] [TextView 2] [TextView 3]
[TextView 4]
------------------------------------------
Actually I dont need a TableLayout. I still can change it in whatever you want. Of course it would be even better if those TextViews can get WRAP_CONTENT as width.
EDIT:
Btw. a LinearLayout with orientation=”horizontal” adds the TextViews at first corret, but on the end it doesn’t wrap to the next line, it just adds them to the right side and it will be splitted, like:
------------------------------------------
[TextView 1] [TextView 2] [TextView 3] [Te
[xt
Vie
w 4
]
------------------------------------------
I think you could try something like that :
– Put a
TableLayoutas root of yourActivity, withFILL_PARENTas width and height.– Then get its width and store it in a variable (mWidth).
– you create a
TableRow, add a firstTextViewand store its width in a variable (mTotalWidth), and you put theTextViewin the row.– When you want to add a new
Textview, you create it, get its width and calculate the sum when you add it to mTotalWidth.Now
ifmTotalWidth < mWidth , you add yourTextViewinto the current row and increment mTotalWidthelseyou create a newTableRow, put yourTextviewin it, and change the value of mTotalWidth to the width of thisTextView.Then you can repeat this for all your views. This can appear a bit messy but I think it could work.