0

Problem: I get a lint error and warning on styles that are working, when defining the orientation of a LinearLayout in a styles file, but not when defining the orientation directly on the element. Even though the property is picked up from the styles file.

I have a base style for all my activities, containing the following:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="StandardActivity">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:orientation">vertical</item>
    </style>
</resources>

In my layout, if I add this code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/StandardActivity">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

    ...

    </LinearLayout>

    ...

</LinearLayout>

On layout_width I get a lint warning:

Use a 'layout_width' of '0dp' instead of 'fill_parent' for better performance

And on layout_height I get a lint error:

Suspicious size: this will make the view invisible, probably intended for 'layout_width'

Everything is working as expecting and the layout takes the orientation attribute set in StandardActivity. However, the error and warning are only valid when the orientation is set to horizontal. How can I get the lint in Android studio to understand that the orientation is set in the style-file?

If a explicitly add the orientation directly to the LinearLayout, the linting error and warning disappears.

Christoffer Karlsson
  • 4,539
  • 3
  • 23
  • 36

1 Answers1

0

There isn't an issue, the IDE is probably behind. The it's assumption made is that the layout_orientation is horizontal, in which case those errors would be correct. But as you've made the layout_orientation=vertical in the style everything is fine. If you were to transfer those variables directly into the layout those errors should go away. PS fill_parent is deprecated, use match_parent

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"   >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

    ...

    </LinearLayout>

    ...

</LinearLayout>
Niza Siwale
  • 2,390
  • 1
  • 18
  • 20