Hadi Eskandari
Hadi Eskandari

Reputation: 26444

Android two ListViews spacing and layout

I have create the following layout, where the UI is consisted of two LinearLayouts, in everyone there is a header textview and a list view. I need to dynamically set the ListView heights so that both display properly.

It is like this right now:

Layout

Look how empty space is wasted below the first ListView while the other one displays scrollbars and can benefit that extra space?

The layout xml looks like this:


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

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

        <TextView android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:text="Current outages"
                  android:paddingLeft="3sp"
                  android:background="@color/listHeader_Background"
                  android:textColor="@color/listHeader_Foreground"/>

        <ListView android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"/>

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

        <TextView android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:paddingLeft="3sp"
                  android:text="Resolved outages"
                  android:background="@color/listHeader_Background"
                  android:textColor="@color/listHeader_Foreground"/>

        <ListView android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="1" />

    </LinearLayout>
</LinearLayout>

Upvotes: 2

Views: 1605

Answers (1)

Robby Pond
Robby Pond

Reputation: 73494

Use WRAP_CONTENT instead of FILL_PARENT on the heights of the Child Layouts.

Upvotes: 5

Related Questions