Pages Navigation Menu

Coding is much easier than you think

How To Create Absolute Layout in an Android Application

How To Create Absolute Layout in an Android Application

In this Tutorial, you will Learn How to create Absolute Layout

Here you go!!!!


Before creating an android application using Eclipse, let us see some of the key terms involved while developing this application.

Key terms involved in this project:

Absolute Layout: The AbsoluteLayout lets you specify the exact location of its children. The location of the views (children of layout while writing activity.xml) can be specified using attributes layout x and layout y both values are mentioned in DP. Absolute positioning is not too much useful in world of various screen resolutions and aspect ratios. You’d usually leave element positioning to be computed by more flexible layouts.

The tutorial is about how to display an activity in absolute layout.

This project is developed in Eclipse 4.2 (Juno) and tested with Android 2.2
** UPDATE: Android Complete tutorial now available here.
If you are new to android application project, to create a new project in Eclipse refer Creation of Android Project.


Now let’s go to the coding section. This project requires following files.

Source Code:

  1. (Activity in absolutelayout)

Activity Files:

  1. activity_absolutelayout.xml -€“ absolutelayout activity

res – Values:

  1. strings.xml -€“ strings available in absolute layout

Manifest file:

  1. AndroidManifest.xml

Here is the coding for the above files.

package com.example.absolutelayout; //Package absolutelayout
import android.os.Bundle;  //A mapping from String values to various Parcelable types.
import; // Required to create an activity.
import android.view.Menu; // Interface for managing the items in a menu.
public class Absolutelayout extends Activity { // all classes extends activity
	protected void onCreate(Bundle savedInstanceState) {// Create an activity/ screen
// displays activity absolutelayout in absolute layout when app starts
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(, menu);
		return true;


<?xml version="1.0" encoding="utf-8"?>
    <!-- Button 1 position mentioned using layout x and layout y attributes-->
      <!-- Button 2 position mentioned using layout x and layout y attributes-->

Note: Absolute Layout is deprecated warning will come. This is due to the fact that, absolute layouts are less flexible and harder to maintain than other types of layouts without absolute positioning. Also, absolute positioning is not too much useful in world of various screen resolutions.

Menu : activity_absolutelayout.xml

<menu xmlns:android="" >




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="8" />

        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />



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

<!-- Application name -->

    <string name="app_name">Absolutelayout</string>
    <string name="menu_settings">Settings</string>


Styles. xml:

<! -- specify properties such as height, padding, font color, font size, background color -->

        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    <style name="AppBaseTheme" parent="android:Theme.Light">
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->


Run the android application:

Android applications can be run on the android devices. You can either connect hardware to the system to test the application or you can use the android virtual devices (AVD) Manager to create/manage the virtual devices running on emulator to run the application.

If you are new to create a Android Virtual Device (AVD), refer Creating Android Virtual Device.

To run the application/ project, Build your project using Project –>  Build Project.

Build project

This will show errors in Console window at the bottom of the working area in case your project contains.

If your build is successful, Run your application using Run –>  Run or Press Ctrl +F11.

Run Project

Upon running the application, the emulator will be launched which displays the AVD on your screen.

You can see your app with the image set during the android project creation in AVD. Upon running the application, the emulator will be launched with the selected/ available AVD created on your screen.

Start Emulator

Emulator loading home page

To test your application, unlock the screen and double click on your app.

AVD Home screen_2

Absolute Layout

Thus the android application project is executed successfully.


Click Here To Share This..!!

%d bloggers like this: