Android XML没有很好的形成?

时间:2011-07-03 11:39:40

标签: xml

'<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/droid_background">
 <TextView  
android:layout_height="wrap_content" 
android:gravity="center_horizontal"
android:text="@string/hello"
android:textColor="#FFFFFF"
android:textStyle="bold"/>

 <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
 <Button
android:drawable="@drawable/toggleSelection"
android:layout_alignBottom="true"
android:layout_alignParentLeft="true" />
 </RelativeLayout> 
 </TableLayout>'

关于这个问题的结果不是很好吗?所有元素都被终止。正确?

2 个答案:

答案 0 :(得分:3)

RelativeLayout关闭两次。

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" />    <!-- here -->
<Button
android:drawable="@drawable/toggleSelection"
android:layout_alignBottom="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>                         <!-- and here again -->

答案 1 :(得分:1)

完整的XML文件应该是:(在RelativeLayout的结束括号中删除/)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/droid_background">
 <TextView  
android:layout_height="wrap_content" 
android:gravity="center_horizontal"
android:text="@string/hello"
android:textColor="#FFFFFF"
android:textStyle="bold"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
 <Button
android:drawable="@drawable/toggleSelection"
android:layout_alignBottom="true"
android:layout_alignParentLeft="true" />
 </RelativeLayout> 
 </TableLayout>