android絕對布局

來源:互聯網
上載者:User

絕對布局由AbsoluteLayout代表。絕對布局就像java AWT編程中的空布局,就是Android不提供任何布局控制而是由開發人員自己通過X座標、Y座標來控制組件的位置。當使用AbsoluteLayout作為版面配置容器時,版面配置容器不再管理子組件的位置、大小---這些都需要開發人員自己控制。使用絕對布局是,每個組件都可指定如下兩個XML屬性 layout_x:指定該組件的X座標 layout_y:指定該組件的Y座標 例子:登入介面 main.xml代碼 01<?xml version="1.0" encoding="utf-8"?>02<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"03android:orientation="vertical"04android:layout_width="fill_parent"05android:layout_height="fill_parent"06>0708<!-- 定義一個文字框,使用絕對位置 -->09<TextView10android:layout_x="20dip"11android:layout_y="20dip"12android:layout_width="wrap_content"13android:layout_height="wrap_content"14android:text="使用者名稱:"/>15<!-- 定義一個文本編輯框,使用絕對位置 -->16<EditText17android:layout_x="80dip"18android:layout_y="15dip"19android:layout_width="wrap_content"20android:layout_height="wrap_content"21android:width="200px"/>22<!-- 定義一個文字框,使用絕對位置 -->23<TextView24android:layout_x="20dip"25android:layout_y="80dip"26android:layout_width="wrap_content"27android:layout_height="wrap_content"28android:text="密碼:"/>29<!-- 定義一個文本編輯框,使用絕對位置 -->30<EditText31android:layout_x="80dip"32android:layout_y="75dip"33android:layout_width="wrap_content"34android:layout_height="wrap_content"35android:width="200px"36android:password="true"/>37<!-- 定義一個按鈕,使用絕對位置 -->38<Button39android:layout_x="130dip"40android:layout_y="135dip"41android:layout_width="wrap_content"42android:layout_height="wrap_content"43android:text="登入"/>44</AbsoluteLayout>java 代碼: view sourceprint?01package com.nuaa.absolutelayout;0203import android.app.Activity;04import android.os.Bundle;0506public class AbsoluteLayoutTest extends Activity {07public void onCreate(Bundle savedInstanceState){08super.onCreate(savedInstanceState);09setContentView(R.layout.main);10}1112}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.