【问题标题】:Unexpected namespace prefix "xmlns" found for tag LinearLayout (xmlns:tools ERROR)为标签 LinearLayout 找到了意外的命名空间前缀“xmlns”(xmlns:tools ERROR)
【发布时间】:2013-05-28 22:30:08
【问题描述】:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <LinearLayout 
    ***

xmlns:tools="http://schemas.android.com/tools" * 此行显示为标签 LinearLayout 找到的错误 Unexpected namespace prefix "xmlns",我在堆栈上尝试了解决方案,但没有得到解决。请帮忙。

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" 
    android:id="@+id/RL">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        android:id="@+id/label1" />


</LinearLayout>
</ScrollView>

【问题讨论】:

    标签: java android xml-namespaces


    【解决方案1】:

    它抱怨tools:context=".MainActivity" 属性是&lt;LinearLayout&gt; 标签的一部分。它不知道tools:前缀是什么意思。

    您需要将xmlns:tools="http://schemas.android.com/tools" 作为属性添加到&lt;ScrollView&gt; 标记。或者,去掉 &lt;LinearLayout&gt; 标签的 tools:context 属性。

    tools:context(以及其他 tools:... 属性)用作 Android 对 XML 文件的 lint 检查的一部分。请参阅here 了解更多信息。

    【讨论】:

    • 我摆脱了工具:context,我是初学者,请原谅我,但这不会导致我的程序发生任何冲突吗?
    • @RidwanWan - 对于您发布的文件,我认为添加命名空间声明或删除 tools:context 属性没有任何区别。这是针对这个特定文件的。一般来说,删除所有tools:* 属性意味着Android lint 工具将没有那么多信息可以使用;因此,它可能会生成虚假警告或无法生成有助于追踪问题的警告。
    • 这听起来很公平,但它解决了问题!谢谢!
    猜你喜欢
    • 2013-02-01
    • 2013-07-04
    • 2013-06-01
    • 2014-04-05
    • 2013-05-03
    • 2013-09-11
    • 2014-02-16
    • 2016-12-18
    • 2013-05-06
    相关资源
    最近更新 更多