【发布时间】:2015-01-20 14:39:00
【问题描述】:
我在 for 循环中运行以下代码。
TableRow r1 = new TableRow(this);
r1 .setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
TextView editLabel = new TextView(this);
editLabel.setText("Label");
EditText editText = new EditText(this);
editText.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
editText.setMaxLines(1);
r1.addView(editLabel);
r1.addView(editText);
tableLayout1.addView(r1);
行被添加到 TableLayout 但 EditText 似乎没有 match_parent 属性对 layout_width 有效。我使用的表格布局是
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0"
android:shrinkColumns="1"
android:id="@+id/attibutesLayout">
</TableLayout>
edittext 的宽度似乎为零,并且随着我输入数据而不断增加。我希望编辑文本具有恒定的宽度以适合列内。
【问题讨论】:
标签: android android-layout android-edittext