首页 文章

error为标记LinearLayout找到意外的名称空间前缀“xmlns”

提问于
浏览
1

我在LinearLayout的“xmlns:android =”http://schemas.android.com/apk/res/android“中有一个错误”意外的命名空间前缀“xmlns”找到标记LinearLayout“ .

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
            android:background="@drawable/wallpaper"
    android:layout_height="match_parent" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>
    </ScrollView>

3 回答

  • 0

    无需为您在 layout.xml 文件中定义的每个布局放置 namespace 属性 . 只能为根级别元素定义名称空间,如下所示:

    <?xml version="1.0" encoding="utf-8"?>
     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
            android:background="@drawable/wallpaper"
    android:layout_height="match_parent" >
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    
    </LinearLayout>
    </ScrollView>
    
  • 0

    删除此行

    xmlns:android="http://schemas.android.com/apk/res/android"
    

    来自你的 LinearLayout . 您只需在根 layout 中添加一次 . 您只能在每个xml中定义一次命名空间

  • 4

    XML似乎格式正确 . 您可以通过更改XML来规避问题,但这并不能解释您收到错误的原因 . 我想我们需要了解更多关于如何解析XML的知识 . 检查其他XML解析器是否接受它 .

相关问题