I have the following xml layout :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" // ==> here I get the error.
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#298EB5"
android:orientation="horizontal" />
</LinearLayout>
</ScrollView>
But I get the lint message :
This LinearLayout should use android:layout_height="wrap_content"
Why do I get this message?
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.
WRAP_CONTENT means that the view wants to be just large enough to fit its own internal content, taking its own padding into account.
In a nutshell, layout_weight specifies how much of the extra space in the layout to be allocated to the View. LinearLayout supports assigning a weight to individual children. This attribute assigns an "importance" value to a view, and allows it to expand to fill any remaining space in the parent view.
LinearLayout
's are designed for stacking elements either side by side or on top of each other. My guess is that this lint warning recommends virtical stacking due to the ScrollView
Documentation:
"All children of a LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding). A LinearLayout respects margins between children and the gravity (right, center, or left alignment) of each child."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With