How to set a EditText in a certain column of a TableLayout?
I have a TableLayout
on one Android Activity UI. It has two columns.
Now I need to add a new row, and put an EditText
box in second column of that new row. And also, I want that EditText
to fill the whole cell. I have some code like this:
TableRow tr = new TableRow(context);
EditText et = new EditText(context);
et.SetMaxLines(4);
开发者_高级运维etText.setLayoutParams(new TableRow.LayoutParams(1)); //set it to the second coloumn
tr.addView(et);
tl.addView(tr); //tl is the tableLayout
It puts the EditText
in the second column fine, but the EditText
is too small. I tried to use
etText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
but that seems to disabled the TableRow.LayoutParams
setting. I guess each control can only have one LayoutParams
setting.
So, how to make the EditText as a 4 lines text editor and also make sure it is in the second column of that row?
Thanks.
Maybe something like:
TableRow.LayoutParams params = TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
params.column = 1;
etText.setLayoutParams(params);
This is for monodroid, but you should be able to convert for java
EditText et = new EditText(this);
var param = new TableRow.LayoutParams(1);
et.LayoutParameters = param;
Just change 1 to whatever column of your table you want the edittext to show up in.
精彩评论