I'm working on a dialog box in android which I intend to make very flexible for different phone-resolutions. Therefore I'm using the layout_weight attribute when building the xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/newGame_linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="3"
android:orientation="horizontal" >
<ListView
android:id="@+id/newGame_InvitedPlayers"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@color/ListView_Background"
android:cacheColorHint="#00000000" >
</ListView>
<ListView
android:id="@+id/newGame_Plugins"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@color/ListView_Background"
android:cacheColorHint="#00000000" >
</ListView>
</LinearLayout>
<Button
android:id="@+id/newGame_sendInvite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Invite Players" />
<TextView
android:id="@+id/newGame_textViewOnlinePlayers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Online Players:" />
<ListView
android:id="@+id/newGame_onlinePlayers"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="2"
android:background="@color/ListView_Background"
android:cacheColorHint="#00000000" >
</ListView>
</LinearLayout>
Here is how it's supposed to look:
And indeed it looks like I want it to.
But when I click the items in the bottom Listview, which removes them from the bottom ListView and adds them to the top left ListView, the bottom Listview decreases in size until I remove the very last item and it disappears completely and looks like this:
I want it to not change in size at all. Even when it's empty.
Even though dp is a very flexible size-unit I don't want to use it in this case, the two top ListViews should take 3/5 of the screen and the bottom one gets the remaining 2/5, and the Button and the TextView should take as little space possible in between.
I've tried change the last Listviews height to match_parent, it doesn't change anything. The listview still disappears when I click the items.