As mentioned in the Introduction section, RelativeLayout
allows Views to be position-relative to each other and the parent. RelativeLayout
is particularly useful for reducing the number of nested layouts, which is very important for reducing memory and processing requirements.
Create a new project and call it RelativeLayout
. Android Studio defaults to using a ConstraintLayout
, which we will replace with a RelativeLayout
for this example. Use the default Phone & Tablet
settings on the Target Android devices
and select Empty Activity
on the Add an Activity to Mobile
dialog.
- Open the
res/layout/activity_main.xml
file and change it as follows:
<?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" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height...