android - 使用数据绑定时Android资源编译失败
问题描述
我试图在我的应用程序中使用 DataBinding 库,然后我发现了这个错误
Android资源编译失败输出:/Users/adham/Desktop/android/ToDo/app/build/intermediates/incremental/m ergeDebugResources/stripped.dir/layout/activity_main.xml:13:错误:重复属性。
命令:/Users/adham/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/563a6f08d33eace272a78ff5e80c3e9b/aapt2-3.2.1-4818971-osx/aapt2 compile --legacy \ -o \ /Users/adham/Desktop/android/ToDo/app/build/intermediates/res/merged/debug \ /Users/adham/Desktop/android/ToDo/app/build/intermediates/incremental/mergeDebugResources/stripped.dir /layout/activity_main.xml 守护进程:AAPT2 aapt2-3.2.1-4818971-osx 守护进程#2 这是 main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/activity_main_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ListView
android:id="@+id/activity_main_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="8dp"
android:background="@drawable/bottombarrounded"
android:gravity="center">
<EditText
android:id="@+id/activity_main_edit_text"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/edittextrounded"
android:hint="@string/edit_text_hint"
android:inputType="textCapSentences|textMultiLine"
android:maxLength="2000"
android:maxLines="4"
android:paddingLeft="32dp"
android:textColor="@color/black"
android:textColorHint="@color/edit_text_color" />
<Button
android:id="@+id/activity_main_post_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="64dp"
android:background="@drawable/roundedbutton"
android:text="@string/post_button"
android:textColor="@color/text_color"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</layout>
我该怎么办 ?
解决方案
LinearLayout
从您的属性中删除此行:
tools:context=".MainActivity"
您不需要传递上下文。它已经得到了上下文,你正试图再次传递它。因此有一个重复的属性。
此外,删除xmlns
您正在使用的属性。它也会导致错误。删除这些行:
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
也删除这个:
xmlns:android="http://schemas.android.com/apk/res/android"