This article documents the implementation of weights within a RelativeLayout

Let’s start with the renderings

Then on the layout file, according to the code

<? The 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="120dp" android:background="@drawable/style_alert_dialog_addplayer"> <EditText android:id="@+id/et_addPlayerName" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_gravity="center" android:layout_centerVertical="true" android:layout_marginStart="16dp" android:layout_marginEnd="50dp" android:background="@drawable/style_edittext_round_bg" android:inputType="text" /> <Button android:id="@+id/btn_addPlayer" android:layout_width="50dp" android:layout_height="120dp" android:layout_alignParentEnd="true" android:background="@null" android:text="@string/add" android:textColor="@color/colorAccent" /> </RelativeLayout>Copy the code

In the layout file, we first set the width and height of the outer RelativeLayout, using the Button to support its height.

Button then aligns Android with the parent layout to the right :layout_alignParentEnd=”true”

Then set android:layout_width= “fill_parent” on the EditText control that implements the weight

Let me just write it down.

Refer to the adaption within RelativeLayout in this article