簡體   English   中英

Android XML 格式不正確

[英]Android XML not well formed

'<?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>
<ToggleButton
android:id="@+id/togglebutton1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Audio"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" 
>
</RelativeLayout>
</TableLayout>'

出現錯誤 XML 解析:在打開<ToggleButton>和關閉</RelativeLayout>之間形成不正確。 我究竟做錯了什么?

您在 TextView 和 ToggleButton 上缺少結束標簽或 /

您似乎沒有<TextView><ToggleButton>的結束標簽。

花一點時間閱讀基本的 XML 文檔結構,您會受益匪淺。 特別是 XML 需要良好的格式 這是一個很好的教程:

http://www.javacommerce.com/displaypage.jsp?name=wellform.sql&id=18238

<?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" /> 
    <LinearLayout
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" > 
        <ToggleButton 
            android:id="@+id/togglebutton1" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:text="Audio" 
            android:layout_alignParentRight="true" 
            android:layout_alignParentBottom="true"  /> 
    </LinearLayout> 
</TableLayout>

假設您不想在此處添加引號,則需要結束 TextViews 和 Toggle Butotns。

試試看這里: http://developer.android.com/guide/topics/ui/declaring-layout.html

將您的代碼更改為:

<?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>
<ToggleButton
android:id="@+id/togglebutton1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Audio"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" 
 />
</RelativeLayout>
</TableLayout>

您沒有關閉 ToggleButton 和 TextView 標簽。 始終注意這一點。 那是常見的錯誤使用

    <ToggleButton /> 

反而。

'<?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">
<ToggleButton
android:id="@+id/togglebutton1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Audio"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TableLayout>'

您的相對布局必須具有高度和寬度屬性

您應該關閉應答器 ToggleButton,有兩種方法可以做到:

<ToggleButton......... > </ToggleButton><ToggleButton........./>

TextView ,因此在編碼時驗證您的所有觀點:)

問候

用它替換您的切換代碼(即關閉它)並根據嵌套在 textview 中的內容為文本視圖()添加一個關閉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM