Sourabh Sourabh - 5 months ago 11
Android Question

View half of its parent's height and width

How do I make an android view half of its parent's width and height? Something like the starred part here:

+-------|-------+
|*******| |
|*******| |
|*******| |
|*******| |
|*******| |
|*******| |
|-------|-------|
| | |
| | |
| | |
| | |
| | |
| | |
+-------|-------+


Edit

Anyone reading this question, you are better off using AppCompat
GridLayout
and use
column_weight
as explained here as nested weights are expensive.

Answer

Some fake layouts and and Layout Weight must do the trick..

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#FFFFFF"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/dummy"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:visibility="invisible" >
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <LinearLayout
        android:id="@+id/dummy"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:visibility="invisible" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/dummy"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:visibility="invisible" >
    </LinearLayout>
</LinearLayout>

</LinearLayout>