绝对布局由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}

更多相关文章

  1. Android开发全程记录(十四)——Android显示gif动画的方法
  2. Android架构组件一 Android(安卓)Architecture Components开发入
  3. android控件框架介绍
  4. Android云通信IM系列(1)-集成与配置
  5. android中布局 padding gravity margin的理解
  6. Android(安卓)study(1)--Intent
  7. Android(安卓)app性能优化解决卡慢顿之布局优化
  8. Android中使用开源框架SlidingMenu构建左滑菜单栏
  9. Android官方架构组件LiveData: 观察者模式领域二三事

随机推荐

  1. Android(安卓)多国语言文件夹
  2. Android获取OAID设备标识
  3. Android(安卓)Gradle Plugin指南(三)——依
  4. Android消息机制之三---Message
  5. Android中ProgressDialog的简单示例
  6. Android(安卓)Studio添加aar依赖的两种方
  7. android project 文件夹
  8. 使用air进行移动app开发常见功能和问题(二
  9. 使用Android系统自带的icon图标
  10. android:shape的使用