佈局管理器 5-----絕對佈局

絕對佈局由AbsoluteLayout表明。絕對佈局就像java AWT編程中的空佈局,就是Android不提供任何佈局控制而是由開發人員本身經過X座標、Y座標來控制組件的位置。當使用AbsoluteLayout做爲佈局容器時,佈局容器再也不管理子組件的位置、大小---這些都須要開發人員本身控制。 java

使用絕對佈局是,每一個組件均可指定以下兩個XML屬性 android

layout_x:指定該組件的X座標 編程

layout_y:指定該組件的Y座標 app

例子:登陸界面 佈局

main.xml代碼 code

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	>

    <!-- 定義一個文本框,使用絕對定位 -->
    <TextView 
        android:layout_x="20dip"
        android:layout_y="20dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="用戶名:"/>
    <!-- 定義一個文本編輯框,使用絕對定位 -->
    <EditText 
        android:layout_x="80dip"
        android:layout_y="15dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="200px"/>
    <!-- 定義一個文本框,使用絕對定位 -->
    <TextView 
        android:layout_x="20dip"
        android:layout_y="80dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密碼:"/>
     <!-- 定義一個文本編輯框,使用絕對定位 -->
    <EditText 
        android:layout_x="80dip"
        android:layout_y="75dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="200px"
        android:password="true"/>
     <!-- 定義一個按鈕,使用絕對定位 -->
    <Button 
        android:layout_x="130dip"
        android:layout_y="135dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登陸"/>
</AbsoluteLayout>

java 代碼: xml

package com.nuaa.absolutelayout;

import android.app.Activity;
import android.os.Bundle;

public class AbsoluteLayoutTest extends Activity {
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

}
相關文章
相關標籤/搜索