###绝对布局AbsoluteLayout
    * android:layout_x="120dp"   在水平方向上偏移120像素
    * android:layout_y="54dp"    在垂直方向偏移54
###相对布局RelativeLayout
    * 组件默认左对齐、顶部对齐
    * 设置组件在指定组件的右边
         android:layout_toRightOf="@id/tv1"
    * 设置在指定组件的下边
        android:layout_below="@id/tv1"
    * 设置右对齐父元素
        android:layout_alignParentRight="true"
    * 设置与指定组件右对齐
         android:layout_alignRight="@id/tv1"
###线性布局LinearLayout
    * android:orientation="horizontal"  在水平方向上线性布局
    * android:orientation="vertical"    在垂直方向上线性布局
    * 设置右对齐
        android:layout_gravity="right"
    * 当竖直布局时,只能左右对齐和水平居中,顶部底部对齐竖直居中无效
    * 当水平布局时,只能顶部底部对齐和竖直居中
    * 使用match_parent时注意不要把其他组件顶出去
    * 线性布局非常重要的一个属性:权重
        android:layout_weight="1"
    * 权重设置的是按比例分配剩余的空间
###帧布局FrameLayout
    * 默认组件都是左对齐和顶部对齐,每个组件相当于一个div
    * 可以更改对齐方式     android:layout_gravity="bottom"
    * 不能相对于其他组件布局
###表格布局TableLayout
    * 每个<TableRow/>节点是一行,它的每一个节点是一列
    * 表格布局中的节点可设置宽高无效
        * 根节点<TableLayout/>的子节点宽为匹配父元素,高为包裹内容
        * <TableRow/>节点的子节点宽为包裹内容,高为包裹内容
        * 根节点<TableLayout/>的节点宽为匹配父元素,高位包裹内容
        * 以上默认属性无法修改
    *根节点中可以设置一下属性,表示让第一列拉伸填满宽度的剩余空间
        * android:stretchColumns="1"

案例一(帧布局):

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<TextView
        android:layout_width="240dp"
        android:layout_height="240dp"
        android:background="#FF0000"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#00FF00"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="160dp"
        android:layout_height="160dp"
        android:background="#0000FF"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:background="#FFFF00"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="#FF00FF"
        android:layout_gravity="center"
        />
     <TextView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:background="#FFFFFF"
        android:layout_gravity="center"
        />
</FrameLayout>

布局结果: 

  

案例二(线性布局);

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        >
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#ff0000"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#ffffff"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#000000"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@android:color/darker_gray"
            />
    </LinearLayout>

<LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        >
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#00ff00"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="@android:color/darker_gray"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#000000"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#ffcc0000"
            />
    </LinearLayout>
</LinearLayout>

事例结果:

  

案例三 相对布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<Button
        android:id="@+id/center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="中间"
        android:layout_centerInParent="true"
        />
    
    <Button
        android:id="@+id/above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="上边"
        android:layout_above="@id/center"
        android:layout_alignRight="@id/center"
        android:layout_alignLeft="@id/center"
        />
    <Button
        android:id="@+id/above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="下边"
        android:layout_below="@id/center"
        android:layout_alignRight="@id/center"
        android:layout_alignLeft="@id/center"
        />
    
    <Button
        android:id="@+id/above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="左边"
        android:layout_toLeftOf="@id/center"
        android:layout_alignTop="@id/center"
        android:layout_alignBottom="@id/center"
        android:layout_alignParentLeft="true"
        />
    <Button
        android:id="@+id/above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="右边"
        android:layout_toRightOf="@id/center"
        android:layout_alignTop="@id/center"
        android:layout_alignBottom="@id/center"
        android:layout_alignParentRight="true"
        />
    
    <Button
        android:id="@+id/above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="左上"
        android:layout_toLeftOf="@id/center"
        android:layout_above="@id/center"
        android:layout_alignParentLeft="true"
        />
    <Button
        android:id="@+id/above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="左下"
        android:layout_toLeftOf="@id/center"
        android:layout_below="@id/center"
        android:layout_alignParentLeft="true"
        />
    
     <Button
        android:id="@+id/above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="右上"
        android:layout_toRightOf="@id/center"
        android:layout_above="@id/center"
        android:layout_alignParentRight="true"
        />
    <Button
        android:id="@+id/above"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="右下"
        android:layout_toRightOf="@id/center"
        android:layout_below="@id/center"
        android:layout_alignParentRight="true"
        />
</RelativeLayout>

事例结果:

  

案例四(表格布局):

 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1"
    >
    <TableRow
        >
        <TextView
            android:layout_column="1"
            android:text="open"
            />
        <TextView
            android:gravity="right"
            android:text="Ctrl-O"
            />
    </TableRow>
    <TableRow >
        <TextView
            android:layout_column="1"
            android:text="save"
            />
        <TextView
            android:gravity="right"
            android:text="Ctrl-S"
            />
        </TableRow>
    <TableRow
        >
        <TextView
            android:text="  "
            />
        <TextView
            android:text="save AS"
            />
        <TextView
            android:text="Ctrl-shift-S"
            />
    </TableRow>
    
    <TextView
        android:layout_height="1dp"
        android:background="#000000"
        />
    
    <TableRow
        
        >
        <TextView
            android:text="X"
            />
        <TextView
            android:layout_span="2"
            android:text="Import"
            />
        
    </TableRow>
    <TableRow
        
        >
         <TextView
            android:text="X"
            />
        <TextView
            android:text="Export"
            />
        <TextView
            android:gravity="right"
            android:text="Ctrl-E"
            />
    </TableRow>
     <TextView
        android:layout_height="1dp"
        android:background="#000000"
        />
    <TableRow
        
        >
        <TextView
            android:layout_column="1"
            android:layout_span="2"
            android:text="Quit"
            />
        
    </TableRow>

</TableLayout>

事例结果:  

  

Android first---常见布局的更多相关文章

  1. android开发中常见布局的注意点

    常见布局的注意点 线性布局: 必须有一个布局方向 水平或者垂直 在垂直布局中 只有左对齐 右对齐 水平居中生效 在水平布局中 只有顶部对齐 底部对齐 垂直居中生效 权重:组件按比例分配屏幕的剩余部分( ...

  2. 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)

    1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM ...

  3. Android 布局学习之——Layout(布局)具体解释二(常见布局和布局參数)

     [Android布局学习系列]   1.Android 布局学习之--Layout(布局)具体解释一   2.Android 布局学习之--Layout(布局)具体解释二(常见布局和布局參数)   ...

  4. Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)

    [Android布局学习系列]   1.Android 布局学习之——Layout(布局)详解一   2.Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)   3.And ...

  5. Android下常见动画

    摘要:Android中常见的的动画有三种:属性动画.补间动画.帧动画. 注.因为前两种内容较多,后补 一.属性动画 二.补间动画 三.帧动画:本质是将一些连贯的图片加载形成连贯的动画效果 1.在Dra ...

  6. Android组件---四大布局的属性详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4372222.html Android常见布局有下面几种: LinearL ...

  7. 14.Android之Layout布局学习

    Android布局主要有5种,接下来学习总结下. 1) 最常见的线性布局 LinearLayout 线性布局是Android布局中最简单的布局,也是最常用,最实用的布局. android:orient ...

  8. 二十一、Android上常见度量单位【xdpi、hdpi、mdpi、ldpi】解读

    术语和概念 屏幕尺寸 屏幕的物理尺寸,以屏幕的对角线长度作为依据(比如 2.8寸, 3.5寸). 简而言之, Android把所有的屏幕尺寸简化为三大类:大,正常,和小. 程序可以针对这三种尺寸的屏幕 ...

  9. [置顶] Android系统五大布局详解Layout

    我们知道Android系统应用程序一般是由多个Activity组成,而这些Activity以视图的形式展现在我们面前,视图都是由一个一个的组件构成的.组件就是我们常见的Button.TextEdit等 ...

  10. Android中常见的MVC模式

    MVC模式的简要介绍 MVC是三个单词的缩写,分别为: 模型(Model),视图(View)和控制Controller). MVC模式的目的就是实现Web系统的职能分工. Model层实现系统中的业务 ...

随机推荐

  1. bzoj1855: [Scoi2010]股票交易--单调队列优化DP

    单调队列优化DP的模板题 不难列出DP方程: 对于买入的情况 由于dp[i][j]=max{dp[i-w-1][k]+k*Ap[i]-j*Ap[i]} AP[i]*j是固定的,在队列中维护dp[i-w ...

  2. SpringBoot项目部署与服务配置

    spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动.其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat).当然你也可以将项 ...

  3. 在PHP与HTML混合输入的页面或者模板中就需要对PHP代码进行闭合

    PHP程序的时候会在文件的最后加上一个闭合标签,如下: <?phpclass MyClass{public function test(){//do something, etc.}}?> ...

  4. spidermark sensepostdata ntp_monlist.py

    试NTP 时间服务器用的,ntp_ip_enum.py,源码如下:#!/usr/bin/env python"""Basic script to pull address ...

  5. 运行WampServer时,提示Exception Exception in module wampmanager.exe at 000F15A0.解决办法

    出现问题:运行WampServer时,提示Exception Exception in module wampmanager.exe at 000F15A0.解决办法 出现问题原因: ①:缺少Visu ...

  6. 一次与iptables有关的Openstack排错

    先说下环境: 宿主机A(192.168.1.242)上运行着实例a(192.168.1.176), 宿主机B(192.168.1.56)上运行着实例b(192.168.1.50). 用户说从实例b上t ...

  7. 往sde中导入要素类报错000732

    sde可以成功连接,可以在Server中注册. 但是向sde中导入要素类报错000732,如图所示. 点击红色圆圈提示 ERROR 000732. 将路径修改为绝对路径即可,如下图所示.

  8. [转]如何将SQL Server表驻留内存和检测

    注意这个功能在SQL2005后已经废弃,因为SQL2005会自动管理哪些表常驻内存. 将SQL Server数据表驻留内存是SQL Server提供的一项功能,在一般小型系统的开发过程中估计很少会涉及 ...

  9. SourceInsight

    进入到Temp Project窗口分别可以以文件列表的方式,列出所有的文件,每个窗体下边有一排按钮,左边的窗口(secondView.cpp)从左至右分别为:按字母顺序排列所有标记.按照文件中行数顺序 ...

  10. windows2003服务器mysql每天定时备份

    1.php利用mysqldump备份数据库,代码如下: <?php /** * 数据库备份 */ $sqlname = $argv[1]; //接受bat或cmd传过来的第一个参数 要备份的数据 ...