Search code examples
androidandroid-tablelayout

Layout Parameters for TableRow views


  1. I have a TableLayout and I need to add TableRows at runtime.
  2. I need to add an ImageView and a TextView to each TableRow and add the row to TableLayout.
  3. And the TextView added to each row should be displayed in multiple lines if the length of the text is much long.
  4. I tried setSingleLine(false), setMaxWidth(100), setMaxLines(3), nothing is working but If I add the TableRow in xml with android:singleLine="false" it shows the text in multiple lines.

Please suggest me.......

SOLVED THROUGH THIS CODE

TableRow.LayoutParams tlparams = new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT);
TextView textView = new TextView(this);
textView.setLayoutParams(tlparams);
textView.setText("New text: " + s);
textView.setSingleLine(false);

Solution

  • The below code will work for you.

    TableRow.LayoutParams tlparams = new TableRow.LayoutParams( 
    TableRow.LayoutParams.WRAP_CONTENT, 
    TableRow.LayoutParams.WRAP_CONTENT); 
    TextView textView = new TextView(this); 
    textView.setLayoutParams(tlparams); 
    textView.setText("New text: ");
    textView.setMaxLines(3);