好吧,所以我写了我的主要xml文件,我很确定它的正确,但我不知道如何在屏幕上显示我的布局。我试图为所有不同的小部件创建变量,并将它们设置为与R.id.main中相同,但它没有在屏幕上显示任何内容。基本上我不明白如何显示在屏幕上xml得到了什么。这是我的代码,请有人解释我哪里出错了。Android布局问题 - 在屏幕上显示xml
public class MinesweeperActivity extends Activity {
private TableLayout all;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
all = (TableLayout)findViewById(R.id.all);
}
}
// this is my xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/all"
android:stretchColumns="*"
android:background="@drawable/bground"
>
<TableRow>
<TextView
android:id="@+id/Timer"
android:layout_column="0"
android:text="000" />
<TextView
android:id="@+id/Counter"
android:layout_column="2"
android:text="000" />
<ImageButton
android:id="@+id/Face"
android:layout_column="1"
android:background="@drawable/faces"
android:layout_height="50px" />
</TableRow>
<TableRow>
<TextView
android:layout_column="0"
android:layout_height="50px"
android:layout_span="3"
android:padding="10dip"/>
</TableRow>
<TableRow>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Mines"
android:layout_width="260px"
android:layout_height="260px"
android:gravity="bottom"
android:stretchColumns="*"
android:layout_span="3"
android:padding="5dip" >
</TableLayout>
</TableRow>
</TableLayout>
谢谢,这解决了它。 – Dave 2012-04-20 13:04:41