How to Implement Android Relativelayout For Designing Attractive User Interface

android relative layout tutorial

Whenever building an Android application, understanding layouts is important to design attractive and appealing user interface. And much like all other layouts, Android relativelayout helps to organize widgets, controls, and relation to one another. All in all, relative layouts are powerful and flexible layout with which, interesting and attractive user interfaces can be designed.

Android Relativelayout Example

Android relative layout is best explained with an example. So in this Android layout tutorial, we’ll be building one project to demonstrate implementation of Android relative layout. In this Android layout design tutorial, we’ll add an EditText control and a button control. Now we’ll place the button to display just to the right of EditText control. This means, we’ll have to define a relative layout with two child controls. The EditText and the Button.

Start Code Integration

Create a new project under file menu, modify the project details and choose appropriate location for the demo project.

relative layout demo

Choose Mini Support SDK to use in this project.

relative layout demo

Lastly, select Add No Activity and click on finish.

relative layout demo

Create XML file

<?xml version="1.0" encoding="utf-8"?>

















        android:text="User :"


















Create Class For Main Activity

package com.relativelayout.demo;


import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView tvuser;

    private EditText edtuser;

    private Button btnSubmit;


    protected void onCreate(Bundle savedInstanceState) {



        // Declare View in initControls()


        // Set on click Listener in set Listner



    private void initControls() {

        tvuser = (TextView) findViewById(;

        edtuser = (EditText) findViewById(;

        btnSubmit = (Button) findViewById(;


    private void setListener() {

        btnSubmit.setOnClickListener(new View.OnClickListener() {


            public void onClick(View view) {





Once you implement the above code, run your project.

It should show output something like this.

Android Relative Layout Tutorial

And Done!

Simple enough don’t you think?

Although this was just a simple demo, but it’s also possible to take it further. Therefore, whenever building an Android app, always consider Android relativelayout for designing the user interface, consult with an expert android app developer, or hire Android app development company, but make sure to implement it the right way.

Grab a free copy of Android Relative Layout Example demo from Github.


Have an App Idea?

Get your free consultation now

Leave a Reply

Your email address will not be published. Required fields are marked *