Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to arrange width and height of relative layout to be half of the screen

Tags:

android

I am developing an android application and I want to set my relative layout's width and height as half of my screen width and height.

Thanks

like image 824
varghesekutty Avatar asked Dec 08 '22 10:12

varghesekutty


2 Answers

Use Parent as the LinearLayout and use weightSum and weight attributes

Sample

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >

  <RelativeLayout
      android:id="@+id/button1"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="50" >

      <!-- Your RelativeLayout Items -->

  </RelativeLayout>

</LinearLayout>
like image 60
Jagadesh Seeram Avatar answered Dec 11 '22 00:12

Jagadesh Seeram


To Divide a Relative layout into two equal relative layouts

    <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<RelativeLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1">
</RelativeLayout>
</RelativeLayout>

and to Divide a linear layout into two equal relative layouts

    <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<RelativeLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1">
</RelativeLayout>
</LinearLayout>
like image 28
Lal Avatar answered Dec 10 '22 22:12

Lal