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:
为该组件添加一个资源id
orientation:
布局中的排列方式,有两种方式: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" ><EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="输入账号" /><EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="输入密码" /><Buttonandroid: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" ><EditTextandroid:id="@+id/name"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="你的名字" /><Buttonandroid: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布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...
标题图 UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个 ...
- Android基础——View和ViewGroup
View和ViewGroup 什么是View? 什么是ViewGroup? 继承层次图 基本属性 常用ViewGroup介绍 线性布局 相对布局 帧布局 常用View介绍 TextView Butto ...
- Android(四)——View和ViewGroup
文章目录 1. 用户界面概述 2. View类常用属性 3. ViewGroup类 4. UI组件的层次结构 1. 用户界面概述 在Android APP中,所有的用户界面元素都是由View和View ...
- 【Android】Android自定义View和ViewGroup知识点汇总
一.View的绘制流程 onMeasure()->onDraw(). 二.ViewGroup的绘制流程 onMeasure()->onLayout()->onDraw()(一般不重写 ...
- Android 让View 和 ViewGroup 同时响应点击或者长按事件
面试的时候,被问到如何让View 和 其 父View 同时响应长按事件. 我还记得当时自己的回答,子View 里面 处理了长按事件,但是返回了false, 没有处理,然后会继续调用到父View 的长按 ...
- new UI-布局之LinearLayout(线性布局)详解
转载自:http://blog.csdn.net/coder_pig/article/details/42344615 --转载请注明出处:coder-pig,欢迎转载,请勿用于商业用途! 小猪An ...
- Android O: View的绘制流程(三):布局和绘制
前一篇文章Android O: View的绘制流程(二):测量中, 我们分析了View的测量流程. 当View测量完毕后,就要开始进行布局和绘制相关的工作, 本篇文章就来分析下这部分流程. 一. ...
- Android常用布局-线性布局和相对布局
1. 线性布局 LinearLayout 线性布局分为水平和垂直两个方向,优点是简单可嵌套,缺点是只能在一个方向进行布局,而且嵌套过多可能存在风险. 1. 标签:<LinearLayout /& ...
- Android自定义view之View的测量过程全解析
Android 应用层开发中绕不开自定义 View 这个话题,虽然现在 Github 上有形形色色的开源库供大家使用, 但是作为一名开发者而言,虽然不提倡重复造轮子,但是轮子都是造出来的.碰到一些新鲜 ...
最新文章
- 伍六七带你学算法——栈的使用
- 相机标定(三) —— 畸变校正
- linux dump_stack
- android 库编译报错,Android Studio编译项目报错
- WF4.0 基础篇 (六) 数据的传递 Arguments 参数
- 前端单页路由《stateman》源码解析
- axis 开发webservice
- CodeVS 1220 数字三角形
- Android 游戏开发中横竖屏切换问题
- 警告:Establishing SSL connection without server’s identity verification is not recommended
- 抢红包算法 c++_【优化求解】基于粒子群算法的光伏电池MPPT控制策略
- APP Launch 优化
- 人脸识别技术细节总结
- 红米note3android5.0,小米红米note3MOSBeta5.0安卓8.1.0来去电归属农历等本地化增强适配...
- 20172307 / 20172311 结对编程项目-四则运算 第三周总结
- 从技术面试官的角度谈谈简历和面试那些事儿
- 怎么清理ug10注册表_最专业的软件卸载利器:不仅可卸载顽固软件,还能清理软件残留和注册表垃圾...
- html怎么制作小黄人,【PS教程】制作一个小黄人
- 摄影师眼中的爱情(完整版)▒┣
- 二元logistics回归