絕對佈局猶如div指定了absolute屬性,用X,Y座標來指定元素的位置
android:layout_x="20px"
android:layout_y="12px"
這種佈局方式也比較簡單,但是在垂直隨便切換時,往往會出問題,而且多個元素的時候,計算比較麻煩。
這樣的方法在直接拖控件的時候顯的比較方便,但是不利於程序的推廣和後期的調整,所以還是建議不使用
絕對佈局。
下面的這個程序是用絕對佈局做的一個登錄界面
xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- 定義一個文本框,使用絕對定位 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dip"
android:layout_y="20dip"
android:text="用戶名:" />
<!-- 定義一個文本編輯框,使用絕對定位 -->
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="80dip"
android:layout_y="15dip"
android:width="200px" />
<!-- 定義一個文本框,使用絕對定位 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dip"
android:layout_y="80dip"
android:text="密 碼:" />
<!-- 定義一個文本編輯框,使用絕對定位 -->
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="80dip"
android:layout_y="75dip"
android:password="true"
android:width="200px" />
<!-- 定義一個按鈕,使用絕對定位 -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="130dip"
android:layout_y="135dip"
android:text="登 錄" />
</AbsoluteLayout>
效果圖如下:參考:http://www.2cto.com/kf/201112/115570.html
整個android的佈局和視圖可以參考這篇博文點擊打開鏈接。寫的非常全!