Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件

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

Android为我们提供了View和ViewGroup的两个子类的集合,提供常用的一些输入控件(比如按钮,图片和文本域等)和各种各样的布局模式(比如线程布局,相对布局,绝对布局,帧布局,表格布局等)。
用户界面布局
在你APP软件上的,用户界面上显示的每一个组件都是使用层次结构View和ViewGroup对象来构成的,比如,每个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中提供了几个常用布局:
LinearLayout线性布局RelativeLayout相对布局FrameLayout帧布局AbsoluteLayout绝对布局TableLayout表格布局GridLayout网格布局
描述一下几个重要的
线性布局:
指子控件以水平或垂直方式排列。
相对布局:
指子控件以控件之间的相对位置或子控件相对于父容器的位置排列。
帧布局:
指所有子控件均放在左上角且后面元素直接覆盖在前面元素之上。
绝对布局:
指子控件通过绝对定位x,y位置来决定其位置摆放。
表格布局:
指以行列的形式放置子控件,每一行是一个TableRow对象或者View对象。
LinearLayout线性布局
常用属性:
id:为该组件添加一个资源idorientation:布局中的排列方式,有两种方式:
horizontal水平
vertical竖直layout_width:布局的宽度,用wrap_content表示组件的实际宽度,match_parent表示填充父容器layout_height:布局的长度,用wrap_content表示组件的实际长度,match_parent表示填充父容器gravity:控制组件所包含的子元素的对齐方式layout_gravity:控制该组件在父容器里的对齐方式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>
RelativeLayout相对布局
RelativeLayout是一个相对布局的视图组,用来显示相对位置的子视图类,在默认情况下,所有子视图对会分布在左上角。
layout_alignParentTop:为true,视图的上边界与父级的上边界对齐layout_centerVertical:为true,将子类放置在父类中心layout_below:将该视图放在资源ID下方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>
GridView网格布局
GridView其实是一个网格一样的视图组件,是一个ViewGroup的二维视图。用适配器可以将布局进行填充。

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

结语
本文主要讲解 Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件
下面我将继续对
Java、Android中的其他知识 深入讲解 ,有兴趣可以继续关注小礼物走一走 or 点赞
Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件的更多相关文章
- android自定义View&自定义ViewGroup(上)
一般自定义view需要重写的方法 void onMeasure(int widthMeasureSpec, int heightMeasureSpec) void onSizeChanged(int ...
- Android中View和ViewGroup介绍
1. 概念Android中的View与我们以前理解的“视图”不同.在Android中,View比视图具有更广的含义,它包含了用户交互和显示,更像Windows操作系统中的window. ViewGro ...
- Android原理View、ViewGroup
Android的UI界面都是由View和ViewGroup及其派生类组合而成的.其中,View是所有UI组件的基类,而ViewGroup是容纳这些组件的容器,其本身也是从View派生出来的.Andro ...
- Android的View和ViewGroup分析
1. 概念 Android中的View与我们曾经理解的"视图"不同.在Android中,View比视图具有更广的含义,它包括了用户交互和显示,更像Windows操作系统中的wind ...
- Android界面View及ViewGroup学习 《转载》
View及ViewGroup类关系 Android View和ViewGroup从组成架构上看,似乎ViewGroup在View之上,View需要继承ViewGroup,但实际上不是这样的. View ...
- Android(java)学习笔记164:Relativelayout相对布局案例
我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout ...
- Android(java)学习笔记107:Relativelayout相对布局
1. Relativelayout相对布局案例: 我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8" ...
- 【Android - 自定义View】之自定义可滚动的流式布局
首先来介绍一下这个自定义View: (1)这个自定义View的名称叫做 FlowLayout ,继承自ViewGroup类: (2)在这个自定义View中,用户可以放入所有继承自View类的视图,这个 ...
- android 自定义 view 和 ViewGroup
---恢复内容开始--- ViewGroup的职能为:给childView计算出建议的宽和高和测量模式 :决定childView的位置:为什么只是建议的宽和高,而不是直接确定呢,别忘了childVie ...
随机推荐
- 初试Python语法小试牛刀之冒泡排序
Python很火,心里很慌,没吃过猪肉,也要见见猪走路. 看了几天Python的语法,大概初步了解了一点点,https://www.liaoxuefeng.com/wiki/0014316089557 ...
- javascript正则表达式中 (?=exp)、(?<=exp)、(?!exp)
(?=exp) 百度百科给的解释:非获取匹配,正向肯定预查,在任何匹配pattern的字符串开始处匹配查找字符串,该匹配不需要获取供以后使用.例如,“Windows(?=95|98|NT|2000) ...
- tensorflow 升级后报错:ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory
我的tensorflow之前的版本是1.2的所以支持cudnn5,但是tensorflow1.3及以上就是支持cudnn6. 查看: /usr/local/cuda/lib64$ ls libcud ...
- 恢复mysql 中root 用户的所有权限
今天在研究数据库的时候不小心吧root用户的权限全给关了.这就尴尬了. 找了半天的解决方案. 如果你的用grant all 无法设定某个用户的权限可以试试这个方法. 1停止mysql服务器.使用ski ...
- 数据库-1055报错-把only_full_group_by去掉
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated c ...
- jdk1.8 HashMap的实现
在了解HashMap之前,我们先进行位运算知识的补充 1.Java 位运算:(都是二进制的运算) << :相当于乘以2的倍数 --->1<<4 =1*2*2*2*2 ...
- day 6 元组、字典、字符串
本节内容 : 1,元组 2,字典 3,字符串作业 produce = [('mac', 9000), ('bicycle', 800), ('computer', 8000), ('book', 50 ...
- python基础之Day7part2 史上最清晰字符编码理解
二.字符编码 基础知识: 文本编辑器存取文件原理与py执行原理异同: 存/写:进入文本编辑器 写内容 保存后 内存数据刷到硬盘 取/读:进入文本编辑器 找到内容 从硬盘读到内存 notepad把文件内 ...
- Netsharp配置文件
一.总体说明 netsharp下需要配置的项目一般是需要独立启动的项目,主要有四个 netsharp-web netsharp-test netsharp-elephant netsharp-donk ...
- tcp、ip、http
tcp是传输层协议,ip是网络层协议,http是应用层协议,简单说就是tcp是传输数据,而http是封装数据. rpc与http的区别是项目大的话,接口间调用变多的话,采用rpc的话,不用像http那 ...