How to use RelativeLayout with weight for width or height in android studio?

17 Views Asked by At

I want to give new positions for views with differents weights for width and height using RelativeLayout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
<!--
To use 0dip for the width or height of view objects
when they are inside a relative layout,
you could analyze how to recalculate the dimensions
to position the view objects in the relative layout
-->
<Button
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="0.3"
    android:id="@+id/b_1"
    android:padding="@dimen/cardview_default_radius"
    android:text="@string/text1"
    android:textSize="12sp"
    android:onClick="controller301"
    />
<Button
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="0.3"
    android:id="@+id/b_2"
    android:padding="@dimen/cardview_default_radius"
    android:text="@string/text2"
    android:textSize="12sp"
    android:onClick="controller301"
    android:layout_below="@+id/b_1"
    />
</RelativeLayout> 
0

There are 0 best solutions below