我对两个XML属性有点困惑:match_parent和fill_parent.似乎两者都是一样的.它们之间有什么区别吗?
我正在尝试向TableLayout添加视图,但它们根本不会显示(我正在模拟器上测试).实际上我写了比这更多的代码,即将textviews添加到tablerows中,但我已经将其缩减到了这一点,即使这样也行不通.知道为什么吗?
这是代码test.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST" >
</TextView>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
和java代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
/* Find Tablelayout defined in test.xml */
TableLayout tl = (TableLayout) findViewById(R.id.tableLayout);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Create a Button to …Run Code Online (Sandbox Code Playgroud)