views:

59

answers:

2

Hello everyone,

I'm trying to put 2 listviews into my layout. The problem is that I don't know the size of each listview in advance. The first listview could have a few items (0, 1, 2 up to roughly 10) and the second listview could have many items (up to 100).

I tried to set the weight of both listviews at 1 but it did not work:

=> If the first listview has only 1 item and the second one 99, you don't see the first item of listview #1 => it's shrinks so much (relative to listview #2) that you don't see it.

So I'm thinking now to split the screen in 2 equals parts (no matter what/no matter the size of each listview) and put the two listviews in each part. Of course it needs to work on any device ... so how do I capture the device screen size, divide it in two and force the listview size to fit in each half of the screen ?

Has anyone done that already ? Is there another option to show two listviews of different sizes on the same layout (should I use a scrollview in some way ? => when the user is reaching the end of the first listview, the second listview appears => is that possible ??)

Thank you for your help and any suggestion ...

Hubert

A: 

Try to set sizes in soft pixels (device independent ones) - like "50sp" or "100sp" - I'm sure you'll find appropriate one

barmaley
+1  A: 

I simply had to "encapsulate" my 2 listviews into 2 separate linearlayouts => these 2 linearlayout have a weight of 1 :

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

                <ListView   android:id="@+id/ListView_NASDAQ100" 
                            android:layout_height="fill_parent" 
                            android:layout_width="fill_parent">

                </ListView>
    </LinearLayout>

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

            <ListView   android:id="@+id/ListView_from_52w_HIGHLOW" 
                        android:layout_height="fill_parent" 
                        android:layout_width="fill_parent">

            </ListView>
</LinearLayout>
Hubert
if you want to see this in action, the app is called DOW JONES for Android, or NASDAQ 100 for Android ... select the button "52 weeks HIGH/LOW" to see this split-screen! cheers, H.
Hubert