Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This LinearLayout should use android:layout_height="wrap_content"?

Tags:

android

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?

like image 208
Robby Smet Avatar asked Sep 14 '12 12:09

Robby Smet


People also ask

What is LinearLayout in android with example?

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.

What does Wrap_content mean?

WRAP_CONTENT means that the view wants to be just large enough to fit its own internal content, taking its own padding into account.

What is the use of layout_weight in android?

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.


1 Answers

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."

like image 125
jnthnjns Avatar answered Oct 13 '22 01:10

jnthnjns