Android: "duplicate attribute" XML error
This error message also happens if you have the same xmlns attribute in different layouts.
In this case, xmlns:tools is repeated in layout and ConstraintLayout. Removing it from one of the layouts should fix the problem.
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="item"
type="com.myapp.SearchSettings" />
</data>
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" <-- remove this line
(it is already in layout tag)
You are setting layout_below
twice.
android:layout_below="@id/text_left"
android:layout_below="@id/text_right"
You can only set this once per widget which in this case is your Button
. You are essentially trying to tell the Button
to place itself below two different items by way of calling android:layout_below
multiple times.
If the end result is not what you expect using only one of the TextViews
you may have to adjust your reference point to something which spans the entire width, or perhaps wrap your TextViews
in a LinearLayout
and use that as your reference point. It may be easier to also switch layout types at the root level, moving to a LinearLayout
and nesting them as needed.
You are setting the layout_below
twice.
If you want the layout in question to be below both of those, try combining both of the text_left
and text_right
into one layout and then use layout_below
and assign it the name you gave to the layout that contains the combination of text_left
and text_right
.
For those, accepted answer didn't work and by any change you are using the android Data Binding then this kind of error may come if some of the attributes are present twice in parent tag as well as child tag. In below example the android:layout_width="match_parent"
android:layout_height="wrap_content"
are used twice in parent as well as in child.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<data>
<variable
name="pdpDescriptionViewModel"
type="com.tottus.ui.productdescription.model.PdpDescriptionViewModel" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</layout>
to solve this remove duplicate attribute from the parent or child and it should work.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="pdpDescriptionViewModel"
type="com.tottus.ui.productdescription.model.PdpDescriptionViewModel" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</layout>