android - 令人费解的Android xmlns错误

标签 android

我在许多 map 示例中都遇到过这样的代码:

<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"
    tools:context=".MainActivity" >

    <fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

但是,对于他们所有人,我都会出错

Description Resource Path Location Type Unexpected namespace prefix "xmlns" found for tag fragment activity_msmap.xml /example/res/layout line 8 Android Lint Problem

在线

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

所以...这里发生了什么?我到处都在示例中看到它,但它会导致我的 Eclipse/Android 出错?另外,为什么在父元素中也定义了相同的 xml 命名空间?

最佳答案

您不能在 xml 布局中定义命名空间两次。 只需将它从您的 fragment 中删除,RelativeLayout 已经定义了 xmlns:android 命名空间。

<fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

关于android - 令人费解的Android xmlns错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15305778/

相关文章:

android - 在发布请求android volley中发送form-urlencoded参数

java - 如果我在房间中使用外键,它会将数据保存在其表中还是单独的表中?

android - 获取插入后的自增值

android - Proguard Gradle 重复的 jar

java - Android自定义 View 布局问题

android - 共享首选项-选择铃声基本实现

android - 我们如何保存和恢复 Android StateFlow 的状态?

android - android中的 Canvas 在不同设备上是成比例的

java - 每 x 秒退出做某事

java - 仅发布问题|应用程序 :lintVitalRelease