Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: "duplicate attribute" XML error

Tags:

android

xml

I have a Layout with a set of widgets on the left side, and others on the right side.

Now I want to put a button in the centre, below to two textviews (one being on the left and the other one being on the right).

I get an error ("duplicate attribute") with the following code:

android:layout_centerInParent="true"
android:layout_below="@id/text_left"
android:layout_below="@id/text_right"

How can I solve this?

Thanks.

like image 718
jaiserpe Avatar asked Dec 20 '12 17:12

jaiserpe


2 Answers

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)
like image 55
live-love Avatar answered Sep 29 '22 00:09

live-love


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>
like image 25
vikas kumar Avatar answered Sep 29 '22 02:09

vikas kumar