Layout Attribute Set to Platform Default

ID

java.android_default_layout_attribute

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Java

Tags

android, layout

Description

Reports XML attributes in Android layout files whose value equals the platform default — for example android:visibility="visible", android:enabled="true", android:focusable="auto" or zero-dimension margin / padding attributes such as android:layout_marginStart="0dp".

Rationale

Redundant attributes add noise to layout files, slow down code review, and tend to lie when the platform default changes between API levels or the View base class is swapped out. Removing them keeps the resource files focused on the attributes that actually carry information.

<!-- Bad: visibility="visible" is the platform default -->
<TextView android:visibility="visible" />

<!-- Bad: zero-dp margin is the platform default -->
<TextView android:layout_marginStart="0dp" />

Remediation

Delete the redundant attribute. If the attribute is there to override a value inherited from a style, switch off the style or set the attribute to a non-default value that actually changes the rendering.

<!-- Good: only the attribute that carries information remains -->
<TextView android:visibility="gone" />