Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextView and text wrapping

I have a TextView inside a TableRow. The text contained in this TextView is tipically larger than the screen. As such, I would like for the the text to wrap into multiple lines.

TableLayout table = (TableLayout)findViewById(R.id.myTable);
TableRow row = new Tablerow(context);
TextView view = new TextView(context);
view.setText(stringWithLotsOfCharacters);
view.setSingleLine(false);
row.add(view);
table.addview(row, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

I tried using "setSingleLine" but it does not have the effect I was looking for.

Any suggestions? Thanks.

like image 636
MyName Avatar asked Apr 01 '11 20:04

MyName


2 Answers

Add android:shrinkColumns="1" for the column you want to wrap to the TableLayout in your layout or android:shrinkColumns="*" if you want to wrap all columns.

You can also do it programmatically with setColumnShrinkable:

public void setColumnShrinkable (int columnIndex, boolean isShrinkable)
like image 186
L. G. Avatar answered Oct 12 '22 01:10

L. G.


view.setHeight(LayoutParams.WRAP_CONTENT);
like image 36
Matt Bishop Avatar answered Oct 12 '22 01:10

Matt Bishop