1 year ago

#357025

test-img

CodingBruceLee

No error Lint even if the same id is used in <include> tag of the xml file

I used two <include> tags in the activity_main.xml and then i just set same id for the two <include> tags. But There is no error Lint. How is it possible? I'm trying to figure this out but can't.
please check all the layout files below.

activity_main.xml

<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">

  <include
      android:id="@+id/include1" <-- same id!!!
      layout="@layout/item1" />

  <include
      android:id="@+id/include1" <-- same id!!!
      layout="@layout/item2" />
</androidx.constraintlayout.widget.ConstraintLayout>

item1.xml

<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

  <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TEXT1"
    android:textSize="36sp"
    android:textStyle="bold"
    android:textColor="@color/black" />
</merge>

item2.xml

<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

  <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TEXT2"
    android:textSize="36sp"
    android:textStyle="bold"
    android:textColor="@color/black"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"/>
</merge>

Thank you in advance :)

android

android-layout

android-xml

0 Answers

Your Answer

Accepted video resources