4

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.

Community
  • 1
  • 1
Sourabh
  • 8,243
  • 10
  • 52
  • 98

2 Answers2

3

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>
David
  • 906
  • 3
  • 11
  • 23
0

there are multiple ways to do so - depends a bit on the context - but one way would be to use layout_weight

ligi
  • 39,001
  • 44
  • 144
  • 244