絕對布局對于頁面的布局管理十分精準,但是比較費時,相容性不好,是以現在一般棄用這種方法。
絕對布局的每個子元件都必須通過以下兩個屬性定義位置:
1.android:layout_x:用于指定元件的X坐标
2.android:layout_y:用于指定元件的Y坐标
但是絕對布局由于相容性太差,現在已棄用。
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.demo.AbsoluteLayout">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="86dp"
android:layout_y="260dp"
android:ems="10"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="24dp"
android:layout_y="280dp"
android:text="密 碼:"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="51dp"
android:layout_x="26dp"
android:layout_y="235dp"
android:text="使用者名:"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="82dp"
android:layout_y="216dp"
android:ems="10"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="-150dp"
android:src="@drawable/test"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="40dp"
android:layout_y="360dp"
android:text="登入"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="220dp"
android:layout_y="360dp"
android:text="關閉"/>
</AbsoluteLayout>