更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680
本篇文章将从LinearLayout、RelativeLayout、FrameLayout、AbsoluteLayout、GridLayout来介绍常用View布局:

一、UI的描述

对于Android应用程序中,所有用户界面元素都是由ViewViewGroup对象构建的。View是绘制在屏幕上能与用户进行交互的一个对象。而对于ViewGroup来说,则是一个用于存放其他ViewViewGroup对象的布局容器!

 
 

Android为我们提供了ViewViewGroup的两个子类的集合,提供常用的一些输入控件(比如按钮,图片和文本域等)和各种各样的布局模式(比如线程布局,相对布局,绝对布局,帧布局,表格布局等)。

二、用户界面布局

在你APP软件上的,用户界面上显示的每一个组件都是使用层次结构ViewViewGroup对象来构成的,比如,每个ViewGroup都是不可见容器,每个ViewGroup视图组用于组织子视图View的容器,而它的子视图View可能是输入一些控件或者在某块区域的小部件UI。如果你有了层次结构树,你可以根据自己的需要,设计出一些布局,但要尽量简单,因为越简单的层次结构最适合性能。

要声明布局,可以在代码中实例化对象并构建,最简单的方法也可以使用xml文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>

三、 在Android中提供了几个常用View布局:

  1. LinearLayout线性布局
  2. RelativeLayout相对布局
  3. FrameLayout帧布局
  4. AbsoluteLayout绝对布局
  5. TableLayout表格布局
  6. GridLayout网格布局

四、 描述一下几个重要的

线性布局:
指子控件以水平或垂直方式排列。

相对布局:
指子控件以控件之间的相对位置或子控件相对于父容器的位置排列。

帧布局:
指所有子控件均放在左上角且后面元素直接覆盖在前面元素之上。

绝对布局:
指子控件通过绝对定位x,y位置来决定其位置摆放。

表格布局:
指以行列的形式放置子控件,每一行是一个TableRow对象或者View对象。

 
image

4.1 LinearLayout线性布局

常用属性:

  1. id:为该组件添加一个资源id
  2. orientation:布局中的排列方式,有两种方式:
    horizontal水平
    vertical竖直
  3. layout_width:布局的宽度,用wrap_content表示组件的实际宽度,match_parent表示填充父容器
  4. layout_height:布局的长度,用wrap_content表示组件的实际长度,match_parent表示填充父容器
  5. gravity:控制组件所包含的子元素的对齐方式
  6. layout_gravity:控制该组件在父容器里的对齐方式
  7. background:为该组件添加一个背景图片

LinearLayout是一个视图组,可以在一个方向垂直或者水平分布所有子项,用android:orientation属性。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入账号" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入密码" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录" />
</LinearLayout>

4.2RelativeLayout相对布局

RelativeLayout是一个相对布局的视图组,用来显示相对位置的子视图类,在默认情况下,所有子视图对会分布在左上角。

  1. layout_alignParentTop:true,视图的上边界与父级的上边界对齐
  2. layout_centerVertical:true,将子类放置在父类中心
  3. layout_below:将该视图放在资源ID下方
  4. layout_toRightOf:将该视图放在资源ID右边
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="你的名字" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentRight="true"
android:text="正确" />
</RelativeLayout>

4.3 GridView网格布局

GridView其实是一个网格一样的视图组件,是一个ViewGroup的二维视图。用适配器可以将布局进行填充。

 
 

4.4 ListView列表组件

ListView是一个用于显示列表的可以滚动的视图组,列表项也可以用适配器进行添加内容的。

 
 

更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680
原文链接:https://www.jianshu.com/p/58d63e31ea18

高级UI晋升之布局ViewGroup(四)的更多相关文章

  1. 高级UI晋升之常用View(三)中篇

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从ViewPager来介绍常用View:文章目录 一.简介 二.基本使用 ...

  2. 高级UI晋升之View渲染机制(二)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 优化性能一般从渲染,运算与内存,电量三个方面进行,今天开始说聊一聊Android ...

  3. 高级UI晋升之常用View(三)上篇

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将先从以下两个内容来介绍常用View: [RecycleView] [Ca ...

  4. 高级UI晋升之触摸事件分发机制(一)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 0. 前言 鉴于安卓分发机制较为复杂,故分为多个层次进行讲解,分别为基础篇.实践 ...

  5. 高级UI晋升之自定义View实战(八)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章自定义流式布局来进行介绍: 一般常见的流式布局由两种,一种是横向的个数固定 ...

  6. 高级UI晋升之自定义view实战(七)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章自定义ViewGroup实现瀑布流效果来进行详解dispatchTouch ...

  7. 高级UI晋升之自定义View实战(六)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从Android 自定义属性动画&Camera动画来介绍自定义V ...

  8. 高级UI晋升之常用View(三)下篇

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从WebView来介绍常用View: 一.WebView介绍 Andro ...

  9. 高级UI晋升之自定义View实战(五)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从自定义View利器Canvas和Paint来进行详解 一.Canvas ...

随机推荐

  1. cocos2d之创建自己的场景类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 1. 首先创建.h的头文件,然后在将一些图片声音素材加到resource文件夹内,最后在创建.cpp文件:         .h头文件中创 ...

  2. Zookeeper安装配置及简单使用

    我使用的CentOS 7阿里云服务器,ZK依赖JDK,需要先安装jdk并配置jdk环境变量. 1.安装wget: yum –y install wget 2.下载Zookeeper(http://mi ...

  3. 神器,阿里巴巴Java代码检查插件

    背景 不久,又一气呵成发布了Eclipse/Intellij Idea下的代码检测插件PC3,可谓是国内代码优秀的检测插件.此插件检测的标准是根据<<阿里巴巴Java开发手册(终极版)&g ...

  4. Android组件内核之Activity调用栈分析(一)

    阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680 导语 我们陈述一下Activity,Activity是整个应用用户交互的 ...

  5. 使用Pandas读取大型Excel文件

    import os import pandas as pd HERE = os.path.abspath(os.path.dirname(__file__)) DATA_DIR = os.path.a ...

  6. 16-python基础-字典

    1.字典的定义 dictionary(字典)是除列表以外python之中最灵活的数据类型. 字典同样可以存储多个数据. 通常用于存储一个物体的相关信息. 和列表的区别 列表是有序的对象集合 字典是无序 ...

  7. shell脚本命令行参数里的空白符

    看一个小脚本 #!/bin/bash #demonstarting the shift command count= while [ -n "$1" ] ; do echo &qu ...

  8. mysql导入.csv文件出错

    1.报错信息 ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cann ...

  9. Jenkins企业应用进阶详解(一)

    Jenkins企业应用进阶详解(一) 链接:https://pan.baidu.com/s/1NZZbocZuNwtQS0eGkkglXQ 提取码:z7gj 复制这段内容后打开百度网盘手机App,操作 ...

  10. secureCRT 如何上传下载文件

    首先连接相应服务器,然后在文件选项当中,打开SFTP功能,这个时候会生成一个新的标签栏. 下载: cd 到要下载文件的路径下 lcd 要存放文件的本地路径 get  {filename} 例: cd  ...