One main draw back of the absolute layout is that it is harder to maintain for different screen sizes (including resolution and aspect ratio) due to hard coded absolute positioning. Due to this reason this layout is deprecated in API level 3.
Here we will discuss this layout in details.
Absolute layout syntax is as under
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- add child view’s here -->
</AbsoluteLayout>
Attributes of the Absolute Layout
Absolute Layout has two main attribute for it child views
android:layout_x : This attribute specify the x coordinate for the child view.
android:layout_Y : This attribute specify the y coordinate for the child view.
Example of an absolute layout.
Here is an example in which we are going to design a Login page using android absolute layout.
XML Code for this is given below
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_x="110px"
android:layout_y="110px"
android:text="User Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="250px"
android:layout_y="80px"
android:width="100px"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<TextView
android:layout_x="110px"
android:layout_y="200px"
android:text="Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="250px"
android:layout_y="150px"
android:width="100px"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log In"
android:layout_x="300px"
android:layout_y="300px"/>
</AbsoluteLayout>
And output screen will be look like this
As we already tells that Absolute Layout for Android is not flexible therefore it depericated and not used commonly in Android app UI design. Now a days the most easy and flexible Layout called the ConstraintLayout is much more commonly used.