【问题标题】:AAPT: error: unbound prefix. in XML androidAAPT:错误:未绑定的前缀。在 XML 安卓中
【发布时间】:2021-04-12 20:42:34
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:androids="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>
        <variable
            name="titleViewModel"
            type="com.example.screen.title.TitleViewModel" />
    </data>

    <LinearLayout
        androids:id="@+id/title_layout"
        androids:layout_width="match_parent"
        androids:layout_height="match_parent"
        androids:gravity="center"
        androids:orientation="vertical"
        tools:context=".screen.title.TitleFragment">

...more

我有一个错误:第一次尝试在 Android 应用程序开发中进行数据绑定时,“”行中的未绑定前缀。

我检查了其他相关线程,他们说这是关于 XML 命名空间的,但这里似乎不是问题,不是吗?如果不是,如何解决?

【问题讨论】:

  • xmlns:android="http://schemas.android.com/apk/res/android"替换xmlns:androids="http://schemas.android.com/apk/res/android"
  • 我是否必须将每个 androids:XXX 更改为 android:XXX?
  • 是的,应该是android 而不是androids
  • 谢谢!它有效,我认为它就像变量一样。但是,我不明白为什么androids 在没有&lt;layout&gt;&lt;data&gt; 标签的情况下工作?

标签: android xml data-binding android-linearlayout


【解决方案1】:

@GottaK 尝试用以下替换

【讨论】:

  • 感谢您的评论。顺便说一句,据我所知,我需要布局标签来进行数据绑定?作为用户,我是 stackoverflow 的新手,如何指出 ADM 评论?
【解决方案2】:
# You will have to removed this line
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
   

<layout xmlns:android="http://schemas.android.com/apk/res/android">
    
        <data>
            <variable
                name="titleViewModel"
                type="com.example.screen.title.TitleViewModel" />
        </data>
<LinearLayout
        androids:id="@+id/title_layout"
        androids:layout_width="match_parent"
        androids:layout_height="match_parent"
        androids:gravity="center"
        androids:orientation="vertical"
        tools:context=".screen.title.TitleFragment">

【讨论】:

  • 谢谢,但是最后一行使用的以下工具不会导致 XML 命名空间问题吗?
  • 是的,但您将使用 MainLayout,就像在 LinearLayout 或 RelativeLayout 中使用给定代码一样,然后您可以使用 xmlns:tools="schemas.android.com/tools" xmlns:app="schemas.android.com/apk/res-auto"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-17
  • 1970-01-01
  • 2012-12-22
  • 2015-05-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多