Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java
  • Android
  • Kotlin
  • Flutter
  • Dart
  • Android with Java
  • Android Studio
  • Android Projects
  • Android Interview Questions
Open In App
Next Article:
Absolute Layout in Android
Next article icon

Absolute Layout in Android

Last Updated : 28 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

An Absolute Layout allows you to specify the exact location i.e. X and Y coordinates of its children with respect to the origin at the top left corner of the layout. The absolute layout is less flexible and harder to maintain for varying sizes of screens that's why it is not recommended. Although Absolute Layout is deprecated now.

Absolute Layout in Android

Some of the important Absolute Layout attributes are the following:

  1. android:id: It uniquely specifies the absolute layout
  2. android:layout_x: It specifies X-Coordinate of the Views (Possible values of this are in density-pixel or pixel)
  3. android:layout_y: It specifies Y-Coordinate of the Views (Possible values of this are in dp or px)

Syntax for Absolute Layout:

XML
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/main"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MainActivity">      <!--sub view 1-->     <View         android:layout_width="wrap_content"         android:layout_height="wrap_content" />      <!--sub view 2-->     <View         android:layout_width="wrap_content"         android:layout_height="wrap_content" /> </AbsoluteLayout> 


Example: In this example, we are going to create a basic application with Absolute Layout that is having two sample views with a background.

Note that we are going to implement this project using the Java language.

Step by Step Implementation

Let us follow the steps to demonstrate the Absolute Layout in Android.

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Step 2: Create the layout file

For this go to app > res > layout > activity_main.xml file and change the Constraint Layout to Absolute Layout and add 3 sample views. Below is the code snippet for the activity_main.xml file.

activity_main.xml:

XML
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/main"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@color/white"     tools:context=".MainActivity">      <!--sub view 1-->     <View         android:layout_width="100dp"         android:layout_height="100dp"         android:background="@color/green"         android:layout_x="0dp"         android:layout_y="0dp"/>      <!--sub view 2-->     <View         android:layout_width="100dp"         android:layout_height="100dp"         android:background="@color/green"         android:layout_x="150dp"         android:layout_y="150dp"/>      <!--sub view 3-->     <View         android:layout_width="100dp"         android:layout_height="100dp"         android:background="@color/green"         android:layout_x="300dp"         android:layout_y="300dp"/>  </AbsoluteLayout> 


Output: You will see that views are having fixed X and Y Coordinates.

Absolute-Layout-in-Android



Next Article
Absolute Layout in Android

A

ankur035
Improve
Article Tags :
  • Technical Scripter
  • Android
  • Technical Scripter 2020
  • Kotlin Android
  • Java-Android

Similar Reads

    Relative Layout in Android
    Relative Layout in Android is a layout that arranges its child views in relation to each other. Unlike Linear Layout, which can make element arrangement complex, RelativeLayout simplifies the process by allowing flexible and dynamic positioning. It enables you to align views relative to each other o
    3 min read
    Android UI Layouts
    Layouts in Android define the user interface and hold UI controls or widgets that appear on the screen of an application. Every Android application consists of View and ViewGroup elements. Since an application contains multiple activities—each representing a separate screen—every activity has multip
    5 min read
    Interesting Facts About Android
    Android is a Mobile Operating System that was released on 23, September 2008. Android is free, open-source operating system and is based on modified version of Linux kernel. Open Handset Alliance (OHA) developed the Android and Google commercially sponsored it. It is mainly designed for touchscreen
    3 min read
    Android RelativeLayout in Kotlin
    RelativeLayout in Android is a ViewGroup subclass, that allows users to position child views relative to each other (e.g., view A to the right of view B) or relative to the parent (e.g., aligned to the top of the parent). Instead of using LinearLayout, we have to use RelativeLayout to design the use
    4 min read
    Spotlight in Android
    Android applications have so many options present within them, so users can interact with the features within the application. Many application provides a spotlight on some of the important features within the application to grab user attention. In this article, we will take a look at How to add Spo
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences