Android AbsoluteLayout Tutorials
Android Sample Codes

Android AbsoluteLayout Tutorials

Android AbsoluteLayout is a layout type that allows you to position your views in the screen using the X, Y coordinates. That is you can specify the exact location of its children by using x and y coordinates.

Android AbsoluteLayout Tutorials

Android AbsoluteLayout

What is a layout in android?. What are all the different types of layouts in android?. Before you proceed the android absolute layout tutorial , refer this link to know the usage of layouts in android and the different types of layout in android.

Absolute layout that lets you specify exact locations (x/y coordinates) of Views in the screen.

In order to align the views in the screen using absolute layout is very difficult because we have to manually specify the locations of the screen accurately. That is why Absolute layouts are less flexible and harder to maintain than other types of layouts in android.

Android AbsoluteLayout Attributes

Following are the important attributes of android AbsoluteLayout.

android:id : This is the ID which uniquely identifies the layout.

android:layout_x : This specifies the x-coordinate of the view.

android:layout_y : This specifies the y-coordinate of the view.

Android AbsoluteLayout Syntax Code

<AbsoluteLayout android:id="@+id/absoluteLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    
</AbsoluteLayout>

Android AbsoluteLayout  Example

The following code can be used to modify your XML layout to check the usage of  working of Absolute layout in android.

activity_main.xml

<AbsoluteLayout android:id="@+id/absoluteLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/btn1"
        android:text="Login"
        android:textColor="@color/colorPrimary"
        android:layout_x="50px"
        android:layout_y="361px" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/btn2"
        android:textColor="@color/colorPrimary"
        android:text="Register"
        android:layout_x="350px"
        android:layout_y="361px" />

</AbsoluteLayout>

The graphical representation of the above code is as follows.

Android AbsoluteLayout Tutorials

 

Leave a Reply

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