Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
What is Absolute Layout?
Need of Absolute Layout:
Advantages of Absolute Layout:
Disadvantages of Absolute Layout:
Attributes in Absolute Layout
Example Application 
Frequently Asked Questions
1. Why is the absolute layout no longer recommended?
2. Is there any better alternate for Absolute layout?
3. What do you mean by containers and layouts in Android?
Last Updated: Mar 27, 2024

Absolute Layout in Android with Example

Author Akshit Pant
0 upvote
Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @


The absolute layout is a layout that allows you to specify the exact placement of its children(widgets) with x/y coordinates. Absolute layouts are less flexible and more challenging to manage than layouts that do not use absolute placement.

Before jumping directly on how Android Studio does this, first knowing the basic knowledge of Kotlin and how to use it is strongly recommended.

So, let us start reading about how Absolute layout works in Android.

What is Absolute Layout?

We can specify the exact place with an Absolute Layout. i.e., the X and Y coordinates of its offspring in relation to the layout's origin in the top left corner.

Need of Absolute Layout:

The motive of using the Absolute layout was to inform the widget about the relative positioning on the screen with other widgets.

Advantages of Absolute Layout:

The only advantage of using an Absolute layout is that it gives us x/y coordinates to place our desired widgets in our layout in a relative fashion with each other.

Disadvantages of Absolute Layout:

Absolute layouts are more difficult to maintain for various mobile screen sizes than other layout kinds because we specify the precise placement of a child view/widget. The use of Absolute layout is deprecated(not recommended), Since the positioning is based on x/y coordinates, which isn't very useful in the world of different screen sizes and aspect ratios.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Attributes in Absolute Layout

The following are the most significant AbsoluteLayout attributes:

  1. android:id: This is the unique identifier(specific ID) for the layout.
  2. android:layout_x: The view's x-coordinate is specified here.
  3. android:layout_y: The view's y-coordinate is specified here.

Note: The x and y coordinates are taken with reference from the origin(top-left of the screen).

Example Application 

Now let us see How we use Absolute layout in our project with a simple example given below in which we will be placing different widgets(TextView, Button, ImageViews) in absolute relation to each other(giving widgets their x/y coordinates); for this, open up the Android Studio, start an empty activity, give a name to your app(Kotlin Absolute layout CN in this case), and let Android do the Gradle syncing.


package com.codingninjas.kotlinabsolutelayoutcn

import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

Let the main activity be in the usual form; we can create and set text and image type dynamically in the main activity file, but for this time, let us do the work from the XML file only.

Now make the activity_main.xml file as per the need of your desired layout.


<?xml version="1.0" encoding="utf-8"?>
<!-- using absolute lay(not recommended)-->

        android:layout_y="0dp" />

        app:srcCompat="@android:drawable/btn_plus" />

        app:srcCompat="@android:drawable/btn_minus" />

        app:srcCompat="@android:drawable/ic_menu_send" />

        android:text="@string/save_to_favourite" />

        app:srcCompat="@android:drawable/ic_lock_idle_low_battery" />






Here, we have created four image views, a text view, and a button inside our Absolute layout and have given them x/y coordinates. Use this exact code in your own compiler and see the difference in layout view in your own device so that you can conclude yourself how Absolute layout changes from device to device(size and aspect ratio) and why it’s deprecated.

Frequently Asked Questions

1. Why is the absolute layout no longer recommended?

Ans:  Absolute layout is deprecated since It is incompatible with various screen resolutions(different screen sizes).

2. Is there any better alternate for Absolute layout?

Ans: Yes, We can use a Relative layout instead of an Absolute layout. As the name implies, views are arranged in relation to one another in a Relative layout.

3. What do you mean by containers and layouts in Android?

Ans: Containers are used to group objects and widgets together. If you have a lot of widgets, you'll need a container with a root element to put them all in. On the other hand, Android comes with a set of view classes that act as view containers, and Layouts is the name for these container classes.


In this article, we learned about Absolute layout and its implementation. We also infer from this article why it’s deprecated and what’s a better alternative.
You can head over to our Android Development Course on the Coding Ninjas Website to dive deep into Android Development and build future applications.
We hope this article has helped you enhance your knowledge of the Android UI Absolute layout. If you want to learn more, check out our Programming Fundamentals and Competitive Programming articles. Do upvote this article to help other ninjas grow.
Happy Coding!

Previous article
MVVM (Model View ViewModel) Architecture Pattern in Android
Next article
Difference between MVC, MVP, and MVVM Architecture in Android
Live masterclass