Using RelativeLayout
As mentioned in the Introduction, the 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.
Getting ready
Create a new project and call it RelativeLayout
. The default layout uses a RelativeLayout
, which we will use to align Views both horizontally and vertically.
How to do it...
- Open the
res/layout/activity_main.xml
file and change it as follows:<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Centered" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content...