android绝对布局

绝对布局由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>
07
08<!-- 定义一个文本框,使用绝对定位 -->
09<TextView
10android:layout_x="20dip"
11android:layout_y="20dip"
12android:layout_width="wrap_content"
13android:layout_height="wrap_content"
14android:text="用户名:"/>
15<!-- 定义一个文本编辑框,使用绝对定位 -->
16<EditText
17android:layout_x="80dip"
18android:layout_y="15dip"
19android:layout_width="wrap_content"
20android:layout_height="wrap_content"
21android:width="200px"/>
22<!-- 定义一个文本框,使用绝对定位 -->
23<TextView
24android:layout_x="20dip"
25android:layout_y="80dip"
26android:layout_width="wrap_content"
27android:layout_height="wrap_content"
28android:text="密码:"/>
29<!-- 定义一个文本编辑框,使用绝对定位 -->
30<EditText
31android: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<Button
39android: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;
02
03import android.app.Activity;
04import android.os.Bundle;
05
06public class AbsoluteLayoutTest extends Activity {
07public void onCreate(Bundle savedInstanceState){
08super.onCreate(savedInstanceState);
09setContentView(R.layout.main);
10}
11
12}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值