0

I have a tablelayout in which each row consists of three textviews. I don't know the number of rows so I can't set the height of the textviews from the XML layout and I need to do that programmatically. The next code displays the textviews but not in proper height.. how to do that programmatically in the code?

        TableRow row= new TableRow(this);
        TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
        row.setLayoutParams(lp);
        row.setGravity(Gravity.CENTER);

        tv1 =new TextView(this);
        tv2 =new TextView(this);
        tv3 =new TextView(this);

        tv1.setText(a);
        tv2.setText(b);
        tv3.setText(c);

        row.addView(tv1,0);
        row.addView(tv2,1);
        row.addView(tv3,2);

        tablelayout.addView(row);
ahooee
  • 275
  • 3
  • 14

1 Answers1

0

In case you want that the TableLayout height matchs to its parent see this post: Android: Stretching rows in TableLayout programmatically

and if you want to have columns with equal width have a look at this:

Set equal width of columns in table layout in Android [duplicate]

ahooee
  • 275
  • 3
  • 14