我正在尝试使用数据绑定,所以我有一个布局根目录和一个Constraintlayout子级,但是在尝试编译时,我得到了AAPT:错误:未绑定前缀错误,即使定义了名称空间。
<?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>
有什么建议吗?
答案 0 :(得分:0)
添加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>
`