0

I am getting error of "duplicate attribute" on the second view of constraint layout as commented below, it doesn't matter if i place any other view on second position. I am getting the same error. xml code is given below:

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<android.support.v7.widget.CardView
    android:id="@+id/cardView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dp"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="30dp"
    android:layout_marginTop="2dp"
    android:background="@android:drawable/dialog_holo_light_frame"
    android:elevation="@dimen/cardview_default_elevation"
    app:cardCornerRadius="18dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="56dp"
            android:layout_marginStart="56dp"
            android:layout_marginTop="18dp"
            android:fontFamily="serif"
            android:text="Popcorns"
            android:textColor="@android:color/black"
            android:textSize="26sp"
            android:textStyle="bold"
            android:translationZ="2dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

  //second view starts from here.
        <RatingBar
            android:id="@+id/ratingBar"
           style="@android:style/Widget.DeviceDefault.Light.RatingBar.Small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="32dp"
            android:layout_marginStart="56dp"
            android:layout_marginTop="8dp"
            android:numStars="5"
            android:progressTint="#fdd835"
            android:rating="3"
            android:stepSize="1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView2"
            app:layout_constraintVertical_bias="0.0"
            card_view:layout_editor_absoluteY="39dp"
            tools:layout_editor_absoluteY="63dp" />


        <TextView
            android:id="@+id/textViewWeight"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp"
            android:paddingBottom="8dp"
            android:text="280 g"
            android:textSize="13sp"
            android:translationZ="2dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="@+id/textView2"
            app:layout_constraintTop_toBottomOf="@+id/ratingBar" />

        <TextView
            android:id="@+id/textViewPrice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:layout_marginEnd="32dp"
            android:layout_marginTop="8dp"
            android:fontFamily="serif"
            android:text="Rs 100"
            android:textColor="#FF0000"
            android:textSize="15sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.86"
            card_view:layout_editor_absoluteX="215dp"
            card_view:layout_editor_absoluteY="54dp"
            tools:layout_editor_absoluteX="216dp"
            tools:layout_editor_absoluteY="56dp" />



    </android.support.constraint.ConstraintLayout>


 </android.support.v7.widget.CardView>

have some other view here

 </android.support.constraint.ConstraintLayout>
Cœur
  • 37,241
  • 25
  • 195
  • 267
burhan sabir
  • 51
  • 1
  • 9
  • The `card_view` and `tools` namespace prefixes currently point to the same namespace, so, for example, on your `RatingBar`, `card_view:layout_editor_absoluteY` and `tools:layout_editor_absoluteY` are the same attribute. The `card_view` prefix should be for your app namespace anyway, but that's redundant, as you already have `app`. Just remove `xmlns:card_view="http://schemas.android.com/tools"` on the ``, and also remove all of the current `card_view` attributes, since they are all `editor` attributes anyway, which the `tools` attributes are already covering. – Mike M. Nov 16 '18 at 18:18
  • Have a look here: https://stackoverflow.com/q/49420636. – Mike M. Nov 16 '18 at 18:33
  • have done what you said. now geting some diffrent errors ERROR: mipmap-anydpi-v26/ic_launcher.xml error: resource drawable/ic_launcher_foreground (aka com.example.burhan.myapplication:drawable/ic_launcher_foreground) not found. mipmap-anydpi-v26/ic_launcher_round.xml error: resource drawable/ic_launcher_foreground (aka com.example.burhan.myapplication:drawable/ic_launcher_foreground) not found. – burhan sabir Nov 16 '18 at 18:38
  • Please refer to my last comment above. – Mike M. Nov 16 '18 at 18:39
  • Thank you sir! solved, can i get some more resources to read about my first problem? just to understand it better? – burhan sabir Nov 16 '18 at 18:46
  • 1
    Well, I've been searching for a duplicate, 'cause I thought there was question here already with the same issue that had a decent explanation in its answer, but I can't find it, atm. Honestly, I'm not sure if there are any official docs that cover XML namespaces, and their use in layouts. I just kinda figured it out as I went. I'll do a little more searching, and let you know if I find anything, but this might be something that you just have to get a handle on with experience. – Mike M. Nov 16 '18 at 18:52

0 Answers0