I know this question has been asked a lot of time, and I've read through a lot of them but I don't seem to find an answer. I'm sorry if there is an answer out there that I've not seen.
My problem is that I want to make a screen that can re-size to any screen size. In order to accomplish that, I don't want to set any kind of static width or height in the layouts.
The problem is that I want to have nested weights. The reason for that is that I have a ListView inside of an LinearLayout in between a TextView and another LinearLayout.
The LinearLayout that contains the ListView is composed of the ListView itself and another LinearLayout.
I want the ListView and the LinearLayout(with the two buttons with arrows) to be weighted. I also want the whole screen to be weighted in the next fashion:
- The four buttons on the bottom of the screen must be weighted
- The TextView, the intermediate LinearLayout (With the ListView) and the Bottom LinearLayout (With the four buttons) must be weighted.
I made a quick representation of the screen so you guys could understand this better.
The solution I thought was to change the most external layout to a RelativeLayout. The problem is that if i do that, The ListView will just push the bottom LinearLayout out of the screen.
Is there a way to weight RealtiveLayout components or at least an implementation with LinearLayout that is not considered "Bad for perfomance"?
I'll put the Layout code next:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/multiPlayerHubLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<TextView
android:id="@+id/multiplayerHubHeaderTextView"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="@string/game_inventory_header" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:layout_weight="10" >
<ListView
android:id="@+id/game_inventory_listView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10" >
</ListView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/game_inventory_upButton"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="@string/game_all_upButton" />
<Button
android:id="@+id/game_inventory_downButton"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="@string/game_all_downButton" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/game_inventory_scanButton"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/game_all_scanButton" />
<Button
android:id="@+id/game_inventory_supportButton"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/game_inventory_support" />
<Button
android:id="@+id/game_inventory_attackButton"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/game_inventory_offensive" />
<Button
android:id="@+id/game_inventory_healingButton"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/game_inventory_healer" />
</LinearLayout>
Thanks in advance!