Android 用户界面(User Interface)

本文详细介绍了Android视图体系的基本概念,包括View和ViewGroup的角色和功能,以及如何通过声明式布局实现灵活的UI设计。此外,还探讨了UI事件处理、菜单创建、自定义UI组件的方法,并解释了视图渲染的过程。
View 基类:
视图对象在屏幕特定矩形区域处理自己的尺寸,布局,绘图,焦点切换,滚动,按键/手势交互.也
接收用户交互事件.

View 是 Widget基类,为之提供服务.
ViewGroup 是 Layout 基类,为之提供服务.

视图体系:

ViewGroup
|
ViewGroup
| |
View ViewGroup
|
View



布局:
声明式布局 main.xml

Widgets:
UI组件

UI 事件:
1.定义一个事件监听器,并使用视图注册
2.重写视图回调方法


Menus:
MENU key
菜单键
定义
onCreateOptionsMenu()
onCreateContextMenu()
回调方法声明菜单项.不需要注册事件监听器在菜单中.

声明式菜单项.


Adapters:
适配器

Styles and Themes:
样式:View
主题:Activity或应用

声明式布局:
使用XML文件来描述布局,避免硬编码.提高布局的灵活性.同时表现与行为分离.

创建菜单:
可选菜单:包括图标菜单和扩展菜单.图标菜单最多支持6个菜单项.不支持单选,多选框.
上下文菜单:
子菜单:作文可选菜单和上下文菜单的子菜单,但不能再嵌套子菜单.

在XML中定义菜单
快捷键


Creating Dialogs:
AlertDialog
ProgressDialog
DatePickerDialog
TimePickerDialog

处理 UI Events:
onClick()
From View.OnClickListener.
This is called when the user either touches the item (when in touch mode), or focuses upon the item with the navigation-keys or trackball and presses the suitable "enter" key or presses down on the trackball.

onLongClick()
From View.OnLongClickListener.
This is called when the user either touches and holds the item (when in touch mode), or focuses upon the item with the navigation-keys or trackball and presses and holds the suitable "enter" key or presses and holds down on the trackball (for one second).

onFocusChange()
From View.OnFocusChangeListener.
This is called when the user navigates onto or away from the item, using the navigation-keys or trackball.

onKey()
From View.OnKeyListener.
This is called when the user is focused on the item and presses or releases a key on the device.

onTouch()
From View.OnTouchListener.
This is called when the user performs an action qualified as a touch event, including a press, a release, or any movement gesture on the screen (within the bounds of the item).

onCreateContextMenu()
From View.OnCreateContextMenuListener.
This is called when a Context Menu is being built (as the result of a sustained "long click"). See the discussion on context menus in Creating Menus for more information.

事件处理器:

onKeyDown(int, KeyEvent) - 按键.
onKeyUp(int, KeyEvent) - 按键.
onTrackballEvent(MotionEvent) - Called when a trackball motion event occurs.
onTouchEvent(MotionEvent) - 触摸屏幕
onFocusChanged(boolean, int, Rect) - 获取和失去焦点

用户通知:
Toast Notification: 弹出一个窗口
Status Bar Notification: 状态条
Dialog Notification: 对话框


应用样式和主题:
styles.xml

自定义UI组件:

AdapterView 绑定数据

常用布局对象:
FrameLayout: 帧布局,所有子对象都定位在左上角,并且重叠放置.
LinearLayout: 线性布局,所有子对象从左到右依次排列或从上到下依次排列.不换行/列.
TableLayout: 表格布局,简单表格行列式布局.
RelativeLayout: 相对布局,相对元素布局.


视图渲染:
视图渲染是从视图树根结点开始.分2个过程.第一个过程计算大小measure,第二个过程确定布局layout.
视图渲染从根结点开始广度优先draw().
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值