-1

I want two set Listviews vertically.
I want them to be 40% and 60% length of vertical screen respectively.

Here is the code:

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

<LinearLayout
  android:layout_weight="0.4" 
  android:layout_width="match_parent"
  android:layout_height="0dp">
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>
<LinearLayout
    android:layout_weight="0.6"
    android:layout_width="match_parent"
    android:layout_height="0dp">

     <ExpandableListView
        android:id="@+id/listEvents"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />
</LinearLayout>
</LinearLayout>

But this doesn't work.
The first ListView takes all the screen.

I have also tried removing the LinearLayout that embeds the two ListViews, but it didn't work either. I also tried with android:layout_height="wrap_content" in both Listviews and didn't work.

If I rotate screen to landscape and after back to port again, it works.
It fails the first instance creation.

Any idea on how to solve it?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Fran
  • 417
  • 2
  • 6
  • 15

1 Answers1

0

This layout will work:

<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     >
     <ListView
         android:id="@+id/lvwView"
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_weight="0.4"
     />
     <ExpandableListView
        android:id="@+id/elvEvents"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.6"
    />
</LinearLayout>

Just don't inherit from ListActivity or ListFragment!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115