Prévia do material em texto
Android RelativeLayout Tutorial with
Example kotlin
by Rohit / July 11, 2018
Android RelativeLayout provides flexibility to arrange a child’s views relative to each other. This
means you can align child view left, right, below, and above to relative another view or parent
layout. RelativeLayout is a very important component in terms of the design user interface in an
android app. Because it can eliminate nested views and groups. It’s Keep Layout Hierarchy flat,
which helps to improve the performance of the android app.
You can find using several nested LinearLayout groups used but maybe you are able to
replace them with a single RelativeLayout .
In this tutorial, we learn how to arrange / position Button , TextView and EditText via
“ RelativeLayout “.
Positioning Views in Android RelativeLayout:
Tutorial
By EyeHunts
Search for...
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 1/12
https://tutorial.eyehunts.com/author/rohit/
https://tutorial.eyehunts.com/android/android-linearlayout-tutorial-example-android-kotlin/
https://tutorial.eyehunts.com/
We are covering some main (basic) attributes (alignment and positioning of widgets) of Relative
Layout with arranging the views and widget in User Interface.
android:layout_alignParent & layout_centerVertical
& layout_centerHorizontal
How to arrange widget or element of app UI Bottom, Left, Top and Right.
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 2/12
Here is code for UI design
android:id
This is the ID which uniquely identifies the layout.
android:id="@+id/btn_bottom"
android:layout_above
TextView is above the Button widget.
android:layout_alignBottom
The button is aligned Bottom of Textview widget.
android:layout_alignRight
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 5/12
The bottom is aligned Right of Textview widget.
android:layout_alignLeft
Textview is aligned Left of Button widget.
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 6/12
This is a basic and important attributes of RelativeLayout.
You can learn more attribute of Relative Layout in an android official
document: https://developer.android.com/reference/android/widget/RelativeLayout.
Complete Example of Android RelativeLayout :
let’s build a complete one simple example, which includes the basic attribute. You can compare
the flat view Hierarchy of RelativeLayout with Android LinearLayout.
Step 1. Create a new project “Build Your First Android App in Kotlin“
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 7/12
https://developer.android.com/reference/android/widget/RelativeLayouthttps://tutorial.eyehunts.com/android/android-linearlayout-tutorial-example-android-kotlin/
https://tutorial.eyehunts.com/android/build-your-first-android-app-in-kotlin/
Step 2. Now add the following code in the activity_main.xml resource file
Step 3. setContentView res layout file in “MainActivity.kt”
package `in`.eyehunt.androidrelativelayout
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Step 4. Run the application, in an emulator or On your android device
Output screenshot Android Relative Layout example :
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 9/12
https://tutorial.eyehunts.com/android/run-android-apps-android-emulator/
Download source code Android Relative layout in kotlin
https://github.com/EyeHunts/AndroidRelativeLayout
Note : This example (Project) is developed in Android Studio 3.1.3 . Tested on Android 9
( Android-P), compile SDK version API 26: Android 8.0 (Oreo)
MinSdkVersion=”15″
TargetSdkVersion=”27″
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 10/12
https://github.com/EyeHunts/AndroidRelativeLayout
Coding in Kotlin
Tags: ANDROID BASIC ANDROID LAYOUT
Leave a Reply
You must be logged in to post a comment.
Recent Posts
Window Memes
Windows memes
Github Memes
Linux memes
JavaScript const keyword | Basics
Categories
Android
Android Interview Questions
Android Kotlin
Android UI
C
CSS
Data structure
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 11/12
https://tutorial.eyehunts.com/tag/android-basic/
https://tutorial.eyehunts.com/tag/android-layout/
https://tutorial.eyehunts.com/shro/?redirect_to=https%3A%2F%2Ftutorial.eyehunts.com%2Fandroid%2Fandroid-relativelayout-tutorial-example-kotlin%2F
https://tutorial.eyehunts.com/memes/window-memes/
https://tutorial.eyehunts.com/java/windows-memes/
https://tutorial.eyehunts.com/memes/github-memes/
https://tutorial.eyehunts.com/memes/linux-memes/
https://tutorial.eyehunts.com/js/javascript-const-keyword-basics/
https://tutorial.eyehunts.com/category/android/
https://tutorial.eyehunts.com/category/android-interview-questions/
https://tutorial.eyehunts.com/category/kotlin-android/
https://tutorial.eyehunts.com/category/android-ui/
https://tutorial.eyehunts.com/category/c/
https://tutorial.eyehunts.com/category/css/
https://tutorial.eyehunts.com/category/data-structures/
HTML
Info
Java
JavaScript
jQuery
JSON
Kotlin
Material Design
Memes
NodeJS
Puzzle
Python
SQL
Tool
TypeScript
Search Topics
Archives
Select Month
Search for...
Copyright © 2014 EyeHunts.com. All Rights Reserved
Neve | Powered by WordPress
26/10/2024, 05:04 Android RelativeLayout Tutorial with Example kotlin - EyeHunts
https://tutorial.eyehunts.com/android/android-relativelayout-tutorial-example-kotlin/ 12/12
https://tutorial.eyehunts.com/category/html/
https://tutorial.eyehunts.com/category/info/
https://tutorial.eyehunts.com/category/java/
https://tutorial.eyehunts.com/category/js/
https://tutorial.eyehunts.com/category/jquery/
https://tutorial.eyehunts.com/category/json/
https://tutorial.eyehunts.com/category/kotlin/
https://tutorial.eyehunts.com/category/android/material-design/
https://tutorial.eyehunts.com/category/memes/
https://tutorial.eyehunts.com/category/nodejs/
https://tutorial.eyehunts.com/category/puzzle/
https://tutorial.eyehunts.com/category/python/
https://tutorial.eyehunts.com/category/sql/
https://tutorial.eyehunts.com/category/tool/
https://tutorial.eyehunts.com/category/typescript/
https://themeisle.com/themes/neve/
https://wordpress.org/