Android TextView and text wrapping

I have a TextView inside a TableRow. The text contained in this TextView is much larger than the screen. Thus, I would like the text to wrap in a few 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 that did not have the effect I was looking for.

Any suggestions? Thank.

+5
source share
2 answers

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

You can also do this programmatically using setColumnShrinkable:

public void setColumnShrinkable (int columnIndex, boolean isShrinkable)
+5
source
view.setHeight(LayoutParams.WRAP_CONTENT);
+1
source

All Articles