android绝对布局
16lz
2021-01-25
绝对布局由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}
更多相关文章
- Android开发全程记录(十四)——Android显示gif动画的方法
- Android架构组件一 Android(安卓)Architecture Components开发入
- android控件框架介绍
- Android云通信IM系列(1)-集成与配置
- android中布局 padding gravity margin的理解
- Android(安卓)study(1)--Intent
- Android(安卓)app性能优化解决卡慢顿之布局优化
- Android中使用开源框架SlidingMenu构建左滑菜单栏
- Android官方架构组件LiveData: 观察者模式领域二三事