Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,445 members, 7,823,037 topics. Date: Thursday, 09 May 2024 at 10:10 PM

Relative Layout (android Development) - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Relative Layout (android Development) (754 Views)

Learning Android Development(diary) / Which Programming Language Is Best And Suitable For Android Development / Android Development - Multiple Screen Support (2) (3) (4)

(1) (Reply)

Relative Layout (android Development) by rexben(m): 2:13am On Mar 03, 2018
Relative Layout

It is compound and complex compared to Linear Layout. In Linear Layout, the views fall in place horizontally or vertically but it is not the same in Relative Layout. If you don't put some "functions" in place, your views will just lie on top each other.

<?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"
android:padding="16dp">
<TextView

android:id="@+id/donald"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Donald"
android:textSize="30sp" />
<TextView

android:id="@+id/soo_yii"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/donald"
android:text="Soo Yii"
android:textSize="30sp" />
<TextView

android:id="@+id/tunde"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/soo_yii"
android:text="Tunde"
android:textSize="30sp" />
<TextView

android:id="@+id/ben"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tunde"
android:text="Ben"
android:textSize="30sp" />
<TextView

android:id="@+id/alice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ben"
android:text="Alice"
android:textSize="30sp" />

</RelativeLayout>

To set text or image or button below any other view, you will use android:layout_below="@id/top"

Working with IDs

You and I were given different names so that we can be easily identified. So, to identify views, we assign ids to them.

To assign an id to a view

android:id="@+id/button"

Referencing a view

To reference an ImageView with id (image) in XML,
android:layout_below="@id/image".

To set a text to the right side of another text. Given that the first text's id is text1.
android:layout_toRightOf="text1"
To set a text to the left side of another text. Given that the first text's id is text1.
android:layout_toLeftOf="text1"
To set a text above another text. Given that the first text's id is text1.
android:layout_above="text1"

To set a text below another text. Given that the first text's id is text1.
android: layout_below="text1".
Another interesting thing about Relative Layout is that you can align views to the parent view group (e.g RelativeLayout).
To align a button to the parent bottom, android:layout_alignParentBottom="true"
To align a button to the top of a parent, android:layout_alignParentTop="true"
To align a button to the left of a parent, android:layout_alignParentLeft="true"
To align a button to the right of a parent, android:layout_alignParentRight="true"

To align a button to the center of a parent, android:layout_centerInParent="true"

(1) (Reply)

List Your Properties Here / How To Make Smartslider Plugin Appear On Homepage / I Build Laravel Applications

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.