android - 为标记 LinearLayout 找到错误意外的命名空间前缀 "xmlns"

标签 android xml

我在 LinearLayout 的“xmlns:android="http://schemas.android.com/apk/res/android"中出现错误“为标记 LinearLayout 找到意外的 namespace 前缀“xmlns”。

    <?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>

最佳答案

无需为您在 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>

关于android - 为标记 LinearLayout 找到错误意外的命名空间前缀 "xmlns",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17508948/

相关文章:

java - 如何修复 Android.support.v7.widget.CardView 类膨胀错误

AppCompatActivity 中未解析的 Android Activity Results API 引用

android - 在 Android 上使用或不使用自定义字体

android - HoneyComb 上的 MonoDroid - 熄灯

Android Vector Drawable 崩溃

c++ - 使用 PugiXML 进行 XML 解析,无限循环

XML::Twig 正在为多行中提供的值添加空换行符

php - 从 XML feed 向 MySQL 数据库插入数据

Java Web 服务异常 - NullPointEreException

c# - xmlNode.SelectSingleNode 始终返回相同的值,即使节点发生变化