android中为了适应各种布局的格式,提供了5种布局格式:

LinearLayout(线性布局)FrameLayout(帧布局)RelativeLayout(相对布局)TableLayout(表格布局)AbsoluteLayout(绝对布局)。

在android的项目中,我们要设计出让人耳目一新的界面,无时无刻都要用到这些布局格式。这些布局文件主要是以xml文件的格式存在,并且保存在/res/layout目录下。此文件夹下存着我们写的各种布局文件。例如:/res/layout/activity_main.xml.

下面我们详细介绍一下5种布局文件:FrameLayout(帧布局)

此布局是最简单的布局形式,所添加的组件都是层叠的方式显示,第一个控件在最底层,最后添加的控件在视图显示的最上层,有点类似堆栈的形式。下面给出自己的一个实例:<?xml  version="1.0" encoding="utf-8"?>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/background"

android:orientation="vertical" >

android:layout_width="match_parent"

android:layout_height="300dip"

android:orientation="vertical" >

android:id="@+id/start"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="startAnimation"

/>

android:id="@+id/stop"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="reversestartAnimation"

/>

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:id="@+id/windmill_layout"

android:layout_width="match_parent"

android:layout_height="80dip" >

android:id="@+id/im_roof"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:src="@drawable/windmill_roof" />

android:id="@+id/im_fan"

android:layout_width="104dp"

android:layout_height="106dp"

android:layout_gravity="center"

android:src="@drawable/windmill_fan" />

android:id="@+id/im_window"

android:layout_width="80dip"

android:layout_height="80dip"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:layout_marginBottom="20dp"

android:src="@drawable/windmill_window" />

这是在RelativeLayout中嵌套一个FrameLayout布局。并且FrameLayout布局中有两个互相重叠的p_w_picpathView对象。

2. AbsoluteLayout(绝对布局)

此布局中的子控件需要指定其坐标的相对位置的横纵坐标,否则此布局会像FrameLayout布局一样被排在左上角。此布局不能自动适应屏幕尺寸,所以少用,这里简单介绍一下定义。

3.TableLayout(表格布局)

定义:把子控件元素放置在行和列中,并且不显示行列和单元格边界线。每一行就是一个TableRow,也可以是一个View对象。在TableRow里面每天加一个控件,代表一列。

属性参数说明:

android:layout_colum :设置控件在TableRow中所处的列。

android: layout_span:设置此控件所跨越的列数。

android:collapseColumns:TableLayout指定的列隐藏,多列隐藏,逗号将隐藏类隔开。

android:StretchColumns:指定的列为可以伸展的列,多列伸展,用逗号隔开。

android:shrinkColmns:设置指定的列为可收缩的列。

4.LinearLayout(线性布局)

定义:在一个方向上(垂直或者水平)对齐所有子元素,一个垂直列表中每一行都只有一个子元素,一个水平列表只是一列高度。<?xml  version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="center_vertical"

android:orientation="vertical" >

android:id="@+id/catalog"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#E0E0E0"

android:textColor="#454545"

android:layout_weight="1.0"

android:paddingLeft="5dip"

android:paddingTop="5dip"

android:paddingBottom="5dip"

android:text="A"/>

android:id="@+id/title"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_gravity="center_vertical"

android:gravity="center_vertical"

android:layout_weight="1.0"

android:textColor="#336598"

android:layout_marginLeft="5dip"

android:paddingTop="10dip"

android:paddingBottom="10dip"

android:text="hhhh"/>

5.RelativeLayout(相对布局)

定义:根据布局中子控件会根据他们设置的参照控件和参数进行相对布局。参照控件可以是父控件,也可以是其他的子控件,但是被参照的空间必须在参照它的控件之前定义。<?xml  version="1.0" encoding="utf-8"?>

android:id="@+id/umeng_socialize_comment_item"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#ffffff"

android:padding="5dp" >

android:id="@+id/umeng_socialize_comment_item_profile_gp"

android:layout_width="50dp"

android:layout_height="130dp"

android:layout_marginLeft="8dp"

android:gravity="center" >

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@null" />

android:id="@+id/umeng_socialize_comment_avatar"

android:layout_width="48dp"

android:layout_height="48dp"

android:layout_marginTop="8dp"

android:layout_centerVertical="true"

android:src="@drawable/umeng_socialize_default_avatar"

android:scaleType="fitXY" />

android:id="@+id/umeng_socialize_comment_item_name"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="8dp"

android:layout_marginTop="5dp"

android:layout_toRightOf="@id/umeng_socialize_comment_item_profile_gp"

android:ellipsize="end"

android:ems="10"

android:maxLines="1"

android:textColor="@color/umeng_socialize_list_item_textcolor"

android:textSize="14sp"

/>

android:id="@+id/umeng_socialize_comment_item_content"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="8dp"

android:layout_marginTop="0dp"

android:layout_toRightOf="@id/umeng_socialize_comment_item_profile_gp"

android:layout_below="@id/umeng_socialize_comment_item_name"

android:maxLength="35"

android:layout_marginRight="18dp"

android:scrollHorizontally="false"

android:ellipsize="end"

android:textColor="#646464"

android:textSize="12sp" />

android:id="@+id/umeng_socialize_comment_item_time"

android:layout_marginTop="0dp"

android:layout_marginLeft="8dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/umeng_socialize_comment_item_content"

android:layout_toRightOf="@id/umeng_socialize_comment_item_profile_gp"

android:textColor="@color/umeng_socialize_text_time"

android:textSize="10sp" />

android:id="@+id/umeng_socialize_comment_item_has_location"

android:layout_marginTop="0dp"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:layout_height="18dp"

android:layout_width="18dp"

android:scaleType="fitXY"

android:visibility="invisible"

android:src="@drawable/umeng_socialize_location_ic"/>

相对布局中的属性参数比较多,也比较重要的布局格式。介绍一下relativeLayout布局的属性参数:

android:layout_centerHorizontal 水平居中

android:layout_centervertical 垂直居中

android:layout_centerInParent 相对于父元素完全居中

android: layout_alignparentBottom 贴近父元素的下边缘

android:layout_alignparentLeft

android:layout_alignParentRight

android:layout_alignparentTop

android:layout_alignwithparentifmissing 如果对应的兄弟元素找不到,就以父元素作为参照物

android:layout_below="id/id-name" 在某元素下面

android:layot_top

android:layout_toLeftof

android:layout_toRightof

android:layout_alignTop 本元素的上边缘和某元素的上边缘对齐

android:layout_alignBottom

android:layout_alignLeft

android:layout_alignRight

android:layout_marginBottom 离某元素底边缘的距离

android:layout_margintop

android:layout_marginleft

android:layout_marginright

android系统五大布局,android 五大布局文件相关推荐

  1. android系统recovery模式,Android系统Recovery模式中文详细说明

    Recovery具体功能: 1.刷系统:新下载好的rom,,直接放sd卡上刷(进nand),,无需windows! 2.像电脑的ghost,,允许用户随意将系统和里面的个人资料备份成一个文件,,并允许 ...

  2. [转] Android系统版本号和Android API level对应表

    平时总会去查 Android系统版本号和Android API level对应关系,有时候上不了Google,网上搜的又不全.这里翻译记录下,顺便给出原文网址:https://developer.an ...

  3. 【Android 性能优化】布局渲染优化 ( 过渡绘制 | 背景设置产生的过度绘制 | Android 系统的渲染优化 | 自定义布局渲染优化 )

    文章目录 一. 背景设置产生的过度绘制 二. Android 系统的渲染优化 1. 透明组件数据传递 2. GPU 存储机制 3. Android 7.0 之后的优化机制 三. 自定义布局渲染优化 一 ...

  4. android 调用下载,使用Android系统提供的DownloadManager来下载文件

    在android2.3以后android系统提供了一个系统组件来供其他app调用来下载东西,使用起来非常方便. 例如我们可以拿来下载app的新版本apk,同时在同时注册一个广播接收器来接收下载完成时D ...

  5. 【Android 系统开发】 Android 系统启动流程简介

    作者 : 万境绝尘 (octopus_truth@163.com) 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/3889548 ...

  6. 【Android 系统开发】Android框架 与 源码结构

    一. Android 框架 Android框架层级 : Android 自下 而 上 分为 4层; -- Linux内核层; -- 各种库 和 Android运行环境层; -- 应用框架层; -- 应 ...

  7. Android系统开发智能机器人,Android智能机器人详解

    今天做了一个智能聊天机器人,其实相对比较简单,用到的知识点如下: 1.listView的熟练使用 2.第三方API的调用,发送数据请求和返回数据解析 3.网络请求时使用的异步任务和Handler 不过 ...

  8. Android系统篇之—-Android中的run-as命令引出升降权限的安全问题(Linux中的setuid和setgid)

    一.前言 最近一周比较忙,没时间写东西了,今天继续开始我们今天的话题:run-as命令,在上周的开发中,遇到一个问题,就是在使用run-as命令的时候出现了一个错误,不过当时因为工作进度的问题,这问题 ...

  9. Android系统篇(二)——Android编译核心Build系统

    <深入解析Android5.0系统> 一书笔记 Android的Build系统非常的庞大,他是基于GUN Make以及shell来构建的,我们主要的面对方向是Android.mk文件,这也 ...

  10. android系统关机广播,android关机方法汇总

    有段时间做系统hook时需要用到系统重启,找了几种重启的方法,还有几种关机的方法,总结一下. 一,发送广播 Broadcast, Intent.ACTION_REQUEST_SHUTDOWN关机广播 ...

最新文章

  1. Openpose+Tensorflow 这样实现人体姿态估计 | 代码干货
  2. 【JDK源码】java.util.concurrent.atomic包常用类详解
  3. [(IBUF driven by I/O terminal ) is unplaced after IO placer?
  4. 秒杀/抢购系统设计优化
  5. 2014 找工作总结
  6. C/C++与lua实现互调
  7. 力扣题目系列:322. 零钱兑换
  8. Java中使用Google zxing生成二维码
  9. 基于java+SpringBoot+HTML+Mysql)疫情防控微信小程序
  10. 微信公众号被动回复消息 Java实现
  11. PowerApps初体验,低代码快速搭建一套五一休假报备管理系统(一)
  12. 计算机英语专业摘要,推荐:计算机毕业论文英文摘要的写作方法
  13. 每日工作问题记录总结(好习惯 打卡2/?)
  14. 为什么比同龄人显老?原来基因变异在作怪
  15. 寻找最小生成树的欧拉路径,即一笔画问题
  16. Zabbix 邮件报警、钉钉报警、微信报警
  17. 【ES6】Promise
  18. .net Application.DoEvents()
  19. uniapp 微信小程序发布
  20. vue如何把值放入数组里面去_vue的数组如何存储数据

热门文章

  1. 如何通过离线安装的方式让sublime text具有TypeScript语法高亮的功能
  2. SAP HTML5 Application Repository
  3. where is page layout xml template being initialized - hard code in ctr
  4. sap.dfa.help.utils.adapters.hm.myadapter
  5. Leo的AR代码学习之create-react-class
  6. 使用Chrome的inspect element注意事项
  7. Marketing Cloud里Odata请求响应结构的解析
  8. where used list repository table WBCROSSGT
  9. How does JdkRegexpMethodPointcut work
  10. nodejs - local installation and global installation