zoukankan      html  css  js  c++  java
  • 绝对布局

          绝对布局由AbsoluteLayout代表。绝对布局就是Android不提供任何布局控制,而由开发人员自己通过X坐标、Y坐标来控制组件的位置。当使用AbsoluteLayout作为布局容器时,布局容器不再管理子组件的位置、大小——这些都需要开发人员自己控制。

          使用绝对布局时,每个子组件都可能指定如下两个XML属性。

    • layout_x:指定该子组件的X坐标。
    • layout_y:指定该子组件的Y坐标。

        实例:登录界面      

       下面介绍一个使用绝对布局开发的登录界面的实例,这个登录界面中所有组件都通过“绝对定位”的方式来指定位置。下面是该登录的界面布局文件。

      

    <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:width="200dp"
        android:layout_height="wrap_content"/>
    <!-- 定义一个文本框,使用绝对位置 -->
    <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="200dp"
        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>

     运行该Activity将会出现图2.15所示的效果。

     

    图2.15绝对布局实例的登录界面

      

  • 相关阅读:
    Java线上应用故障排查之一:高CPU占用【转】
    JAVA 之 Tomcat知识框架【转】
    FileZilla 配置备份与还原【转】
    linux删除第几天日志【原创】
    sar命令使用【转】
    Mysql Group Replication 简介及单主模式组复制配置【转】
    grep 中的正则表达式【转】
    java程序out of memory【转】
    Java笔记18:JUnit单元测试
    Java笔记17:导出可执行jar包
  • 原文地址:https://www.cnblogs.com/wolipengbo/p/3341425.html
Copyright © 2011-2022 走看看