View half of its parent's height and width

How do I make an android equal to half of its parent's width and height? Something like a starring role here:

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

      

Edit

Anyone reading this question, you are better off using AppCompat GridLayout

and using column_weight

as described here as nested weights are expensive.

+3


source to share


2 answers


Some fake mockups and mockup The mockup should 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>

      

+2


source


there are several ways to do this - slightly context dependent, but one way would be to use layout_weight



-1


source







All Articles