(#) Obsolete layout params !!! WARNING: Obsolete layout params This is a warning. Id : `ObsoleteLayoutParam` Summary : Obsolete layout params Severity : Warning Category : Performance Platform : Android Vendor : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 Since : Initial Affects : Resource files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ObsoleteLayoutParamsDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ObsoleteLayoutParamsDetectorTest.java) Copyright Year : 2011 The given layout_param is not defined for the given layout, meaning it has no effect. This usually happens when you change the parent layout or move view code around without updating the layout params. This will cause useless attribute processing at runtime, and is misleading for others reading the layout so the parameter should be removed. !!! Tip This lint check has an associated quickfix available in the IDE. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/wrongparams.xml:11:Warning: Invalid layout param in a FrameLayout: layout_weight [ObsoleteLayoutParam] android:layout_weight="1" ------------------------- res/layout/wrongparams.xml:23:Warning: Invalid layout param in a LinearLayout: layout_alignParentLeft [ObsoleteLayoutParam] android:layout_alignParentLeft="true" ------------------------------------- res/layout/wrongparams.xml:24:Warning: Invalid layout param in a LinearLayout: layout_alignParentTop [ObsoleteLayoutParam] android:layout_alignParentTop="true" ------------------------------------ res/layout/wrongparams.xml:33:Warning: Invalid layout param in a LinearLayout: layout_alignBottom [ObsoleteLayoutParam] android:layout_alignBottom="@+id/button1" ----------------------------------------- res/layout/wrongparams.xml:34:Warning: Invalid layout param in a LinearLayout: layout_toRightOf [ObsoleteLayoutParam] android:layout_toRightOf="@+id/button1" --------------------------------------- res/layout/wrongparams.xml:42:Warning: Invalid layout param in a LinearLayout: layout_alignLeft [ObsoleteLayoutParam] android:layout_alignLeft="@+id/button1" --------------------------------------- res/layout/wrongparams.xml:43:Warning: Invalid layout param in a LinearLayout: layout_below [ObsoleteLayoutParam] android:layout_below="@+id/button1" ----------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: `res/layout/wrongparams.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Button" /> <LinearLayout android:id="@+id/relativeLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="17dp" android:layout_marginTop="16dp" android:text="Button" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/button1" android:text="Medium Text" android:textAppearance="?android:attr/textAppearanceMedium" /> <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button1" android:layout_below="@+id/button1" android:text="RadioButton" /> </LinearLayout> <TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button3" android:layout_column="0" android:layout_span="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Button" /> </TableRow> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Button" /> </TableLayout> <GridLayout android:id="@+id/gridLayout1" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button10" android:layout_column="0" android:layout_row="0" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </GridLayout> </FrameLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ObsoleteLayoutParamsDetectorTest.java) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test found for this lint check, `ObsoleteLayoutParamsDetector.test`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. (##) Suppressing You can suppress false positives using one of the following mechanisms: * Adding the suppression attribute `tools:ignore="ObsoleteLayoutParam"` on the problematic XML element (or one of its enclosing elements). You may also need to add the following namespace declaration on the root element in the XML file if it's not already there: `xmlns:tools="http://schemas.android.com/tools"`. ```xml <?xml version="1.0" encoding="UTF-8"?> <include xmlns:tools="http://schemas.android.com/tools" tools:ignore="ObsoleteLayoutParam" ...> ... </include> ``` * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: ```xml <?xml version="1.0" encoding="UTF-8"?> <lint> <issue id="ObsoleteLayoutParam" severity="ignore" /> </lint> ``` Instead of `ignore` you can also change the severity here, for example from `error` to `warning`. You can find additional documentation on how to filter issues by path, regular expression and so on [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). * In Gradle projects, using the DSL syntax to configure lint. For example, you can use something like ```gradle lintOptions { disable 'ObsoleteLayoutParam' } ``` In Android projects this should be nested inside an `android { }` block. * For manual invocations of `lint`, using the `--ignore` flag: ``` $ lint --ignore ObsoleteLayoutParam ...` ``` * Last, but not least, using baselines, as discussed [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).