【问题标题】:Unexpected namespace prefix "xmlns" for tag fragment标记片段的意外命名空间前缀“xmlns”
【发布时间】:2013-05-06 20:53:13
【问题描述】:

尝试对 XML 文件进行一些更改并引发新问题:

她的密码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        xmlns:map="http://schemas.android.com/apk/res/android"
        map:id="@+id/map"
        map:name="com.google.android.gms.maps.MapFragment"
        map:layout_width="wrap_content"
        map:layout_height="250dp" />

</LinearLayout>

出现错误

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

标签片段的非预期命名空间前缀“xmlns”

【问题讨论】:

标签: android xml


【解决方案1】:

不确定我在这里是否有帮助,但在我的情况下,我只在 RelativeLayout 中声明了一次命名空间

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

     <fragment class="com.blablabla.MyFragment"
            android:id="@+id/fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
</RelativeLayout>

我没有在片段中再次声明命名空间,如上所示。据我所知,命名空间只在父 ViewGroup 中声明过一次

【讨论】:

  • 是的,但它涉及相同的命名空间。我不知道为什么,但你的灵魂消除了错误。检查
  • 好的,如果这解决了您的问题,请告诉我。我很好奇,因为我 100% 确定。
  • 很高兴知道!我猜一个 ViewGroup(及其子项)只能有一个命名空间。所以声明两次会报错。
【解决方案2】:

如果我不得不猜测,你很可能会遇到this bug in the build tools

【讨论】:

  • 所以没有办法实现这一点 - Map 和例如 TextView 在同一个活动中?
  • 如果有一个名为“Endomondo 运动追踪器”的地狱应用程序如何在同一活动中使用地图和其他内容?
  • @krzakov:“所以没有办法实现这一点 - 地图和例如 TextView 在同一个活动中?” - 当然。只是不要使用xmlns:map,而是在Java 中设置值。 “如果有一个名为“Endomondo 运动追踪器”的地狱应用程序如何在同一活动中使用地图和其他东西的错误? -- 也许他们的开发人员使用较少的脏话。
猜你喜欢
  • 2013-05-03
  • 2013-09-11
  • 2013-02-01
  • 2013-06-01
  • 2014-04-05
  • 2013-05-28
  • 2013-07-04
  • 2016-12-18
  • 2014-02-16
相关资源
最近更新 更多