I have a LinearLayout that contains sublayouts which essentially mimick a 3×2 grid. Each sublayout takes up an equal amount of space across the screen (in width). Now, I’m looking to have the two rows of sublayouts stretch in height so that each takes up 50% of the screen. I’ve tried playing around with the weights, however I don’t know how to modify my existing layout code without messing up the existing weights in place used for the widths. Can anyone provide me with some help? Thanks! Here is my layout code:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_marginBottom="2dip"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginRight="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage1"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage1"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage2"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage2"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginLeft="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage3"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage3"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginRight="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage4"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage4"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage5"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage5"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginLeft="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage6"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage6"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Apply equal android:layout_weight (for example 50) values on the two “main-parent” LinearLayouts in your existing code. This will make them each take half of any existing free space.
Then put all of your your code in another new LinearLayout. This new one should be set to fill-parent in both width and height. Its orientation should be vertical.
This should get you on the way but you will probably have to tweak your existing code to make it appear exactly as you want.
I run a short test using this code: