Reputation: 60919
I have a vertical linear layout with two ListViews. I want the top ListView to take up 50% of the screen. I want the bottom listivew to take up 50% of the screen. How can I do this in XML?
Upvotes: 2
Views: 4722
Reputation: 10623
Set Vertical LinearLayout to have height:fill_parent
and then set the weight of each ListView to "1" e.g. android:layout_weight="1"
Upvotes: 2
Reputation: 23432
The following layout should work
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
How this works:
wrap_content
) is divided up between all the views with no height and a layout_weight
(layout_weight of View) / (Sum of layout_weights in parent ViewGroup)
(Sum of layout_weights in parent ViewGroup) = 2
and (layout_weight of View) = 1
for each ListView
, so each ListView
occupies 1/2
of the available spaceUpvotes: 13