Matching View Id

ID

kotlin.android_matching_view_id

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Kotlin

Tags

android, reliability

Description

Flags Android layout XML where a relative-positioning attribute such as android:layout_above, android:layout_below, android:layout_toLeftOf, android:layout_alignTop, etc. references an @id/…​ that is not declared in the same layout file.

Rationale

RelativeLayout and related parents resolve positioning references at inflation time by looking up sibling ids declared with @+id/. A missing target id is silently ignored: the affected view falls back to (0,0) and overlaps other children, producing layout bugs that are hard to diagnose at runtime.

<!-- Bad: layout_above references an id that does not exist -->
<RelativeLayout>
  <TextView android:id="@+id/footer" />
  <TextView android:layout_above="@id/header" />
</RelativeLayout>

Remediation

Declare the referenced view with android:id="@+id/header" in the same layout file, or correct the reference to point at an id that already exists.

<!-- Good: target id is declared locally -->
<RelativeLayout>
  <TextView android:id="@+id/header" />
  <TextView android:layout_below="@id/header" />
</RelativeLayout>