• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Dynamic text wrap

Renji

Newbie
Hi,

In my application i am dynamically creating a table layout. In each row of the table layout have 3 text views. but the auto wrap of the text is not working on these text views in multiple screen resolutions.
 
To make textview wrap in table row which is dynamically created you need to use layout_weights. Add a layout_weight of 2 to table row and 1 for text views.

TableRow.LayoutParams lp = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 2f);
TableRow tr = new TableRow(tl.getContext());
tr.setLayoutParams(lp);

For text view
tv.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

If your table columns get disturbed, then make your text view width to 0 pixels to get equal column width
tv.setWidth(0);
 
Back
Top Bottom