Absolute Layout
In Absolute Layout specifies exact location (x/y co-ordinates) of its children. Absolute Layouts are less flexible and harder to maintain than other layouts.
Important attributes of Absolute Layout:
Exmaple:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/AbsoluteLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_x="30dp"
android:layout_y="100dp"
android:text="OK" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_x="160dp"
android:layout_y="100dp"
android:text="Cancel" />
</AbsoluteLayout>
Output
Important attributes of Absolute Layout:
Attribute
|
Description
|
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.
|
Exmaple:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/AbsoluteLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_x="30dp"
android:layout_y="100dp"
android:text="OK" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_x="160dp"
android:layout_y="100dp"
android:text="Cancel" />
</AbsoluteLayout>
Output
Comments
Post a Comment