【问题标题】:AAPT: error: unbound prefix error when using androidx.constraintlayout.widget.ConstraintLayoutAAPT:错误:使用 androidx.constraintlayout.widget.ConstraintLayout 时出现未绑定前缀错误
【发布时间】:2020-01-30 15:38:28
【问题描述】:

我正在尝试使用数据绑定,因此我有一个布局根和一个约束布局子,但是在尝试编译时我得到 AAPT: error: unbound prefix error,即使命名空间已定义。

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:bind="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".View.levels.LevelsActivity">
    <data >
        <variable name="game" type="com.example.gameapp.Model.Game"/>
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        bind:layout_width="match_parent"
        bind:layout_height="match_parent">

    <Button
        bind:id="@+id/Levels_9"
        bind:layout_width="79dp"
        bind:layout_height="79dp"
        bind:layout_marginStart="283dp"
        bind:layout_marginTop="335dp"
        bind:text="9"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
       />

    <Button
        bind:id="@+id/Levels_3"
        bind:layout_width="79dp"
        bind:layout_height="79dp"
        bind:layout_marginStart="283dp"
        bind:layout_marginTop="76dp"
        bind:text="3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
 />



    <TextView
        bind:id="@+id/LevelStatus"
        bind:layout_width="72dp"
        bind:layout_height="60dp"
        bind:text="@{game.levelUpTo}"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.866"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.87" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

有什么建议吗?

【问题讨论】:

标签: android android-layout android-constraintlayout


【解决方案1】:

添加 Android 命名空间

应该添加 xmlns:android="http://schemas.android.com/apk/res/android" 属性.. `

<?xml version="1.0" encoding="utf-8"?>
     <layout xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools"
     tools:context=".View.levels.LevelsActivity">
     <data >
            <variable name="game" type="com.example.gameapp.Model.Game"/>
       </data>

     <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

     <Button
            android:id="@+id/Levels_9"
            android:layout_width="79dp"
            android:layout_height="79dp"
            android:layout_marginStart="283dp"
            android:layout_marginTop="335dp"
            android:text="9"
            android:layout_constraintStart_toStartOf="parent"
            android:layout_constraintTop_toTopOf="parent"
           />

        <Button
            android:id="@+id/Levels_3"
            android:layout_width="79dp"
            android:layout_height="79dp"
            android:layout_marginStart="283dp"
            android:layout_marginTop="76dp"
            android:text="3"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
          />



        <TextView
            android:id="@+id/LevelStatus"
            android:layout_width="72dp"
            android:layout_height="60dp"
            android:text="@{game.levelUpTo}"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.866"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.87" />

    </androidx.constraintlayout.widget.ConstraintLayout>
    </layout>

`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 2012-08-07
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多