Android UI
Android 开发APP中所有的用户界面元素都是View和ViewGroup的对象构成的。View是绘制在屏幕上的用户能与之交互的一个对象。而ViewGroup则是一个用于存放其他View(和ViewGroup)对象的布局容器!
View:所有可视化控件的父类,提供组件描绘和时间处理方法
ViewGroup: View类的子类,可以拥有子控件,可以看作是容器 Android UI中的控件都是按照这种层次树的结构堆叠得,而创建UI布局的方式有两种, 自己在Java里写代码或者通过XML定义布局,后者显得更加方便和容易理解! 也是我们最常用的手段!另外我们一般很少直接用View和ViewGroup来写布局,更多的 时候使用它们的子类控件或容器来构建布局!
1 布局
1.1布局分类
- 线性布局 LinearLayout
- 相对布局 RelativeLayout
- 帧布局 FrameLayout
- 绝对布局 AbsoluteLayout
- 表格布局 TableLayout
- 百分比布局 PercentFrameLayout
- 网格布局 GridLayout
- 约束布局 ConstraintLatout
1.2 布局属性
在学习Andoid开发中了解其布局分类的特性不算复杂,但是在实际开发中设置布局属性的时候总会出现问题,有一些布局属性是共有属性,而有一些是私有特性。
- 公共属性
属性 | 作用 | 具体 |
---|---|---|
layout_width、layout_height | 设置控件的宽、高 | layout_with=" " ; layoutheight="" |
layout_marginXXX | 设置控件边缘相对于父控件的边距 | layout_marginLeft=""; layout_marginRight=""; layout_marginTop=""; layout_marginBotton="" |
paddingXXX | 控件内容的边缘相对控件的边距 | padding_left=" "; paddingRight=" "; paddingTop=""; paddingBotton="" |
layout_gravity | 控件相对于父控件的剧中位置 | layout_gravity="center";正居中layout_gravity="center_horizontal";水平居中 layout_gravity="center_vertical";垂直居中 |
gravity | 控件内容相对于控件的居中位置 | gravity="center"; gravity="center_horizontal"; gravity="center_vertical" |
- 私有属性
2 控件
2.1 常用控件
- TextView 文本框
- EditText 编辑框
- CheckBox 复选框
- Button 按钮
- RadioButton 单选框
- Spinner
- ScrollView
- ProgressBar
- ImageView
- ImageButton
2.2 视图
- GridView 网格视图
- ListView 列表视图
- RecycleView 滚动视图
-
Menu
- Option Menu 选项菜单
- Context Menu 上下文菜单
- Sub Menu 子菜单
-
Dialog
- AleryDialog 警告对话框
- ProgressDialog 进度对话框
- DatePickerDialog 时间选择对话框
- Others
- Toast
- Notification
- PopupWindow
2.3 自定义控件
- ViewPager
- TabHost 选项卡
2.4 开源控件
-
EditText
- PullRefresh
- StatusBar
-
TextView
- 可扩展的Layout ExpandableLayout
- Toast
1.#### SuperToasts -
TabLayout
- 1
-
表盘
-
Chart
-
Dialog
3 XML
布局定义用户界面的视觉结构一般可以通过两种方式声明布局:
1.在XML文件声明UI元素
2.运行时实例化元素 通过编程创建View对象和ViewGroup对象
3.1 XML文件编写
您可以利用 Android 的 XML 词汇,按照在 HTML 中创建包含一系列嵌套元素的网页的相同方式快速设计 UI 布局及其包含的屏幕元素。
每个布局文件都必须只包含一个根元素,并且该元素必须是视图对象或 ViewGroup 对象。定义根元素之后,即可再以子元素的形式添加其他布局对象或小部件,从而逐步构建定义布局的视图层次结构。例如,以下这个 XML 布局使用垂直 LinearLayout 来储存一个 TextView 和一个 Button:
`
<?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>
`
3.2 加载XML文件资源
每一个xml布局文件会被编译到一个View资源中。为了加载布局文件资源,我们需要在Activity的OnCreate()方法中通过调用setContentView方法加载布局文件资源。
4 高级UI
- Fragment
- ActionBar
- ViewFlipper
5 样式和主题
6 布局优化
include、ViewStub、merge
[1] Android学习—— Android布局
[2] 如何自学Android
[3] Android基础:常用布局介绍&使用
[4] Android布局概述
[5] Android样式(style)和主题(theme)
[6] 深入探索Android布局优化(上)
[7] 那些年收藏的Android开源库集合
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。