一、In Android you can customize views in three ways:

1、Custom views (by extending the View class);

2、Compound views/controls(by composing other controls through extending one of existing Layout classes);

3、Custom layouts( by extending the ViewGroup class);

二、the custom view

1、how to embed the costom view in any Android layouts;

2、how the cusotm view responds to touch events;

3、how the custom view remembers states as you rotate the device;

4、how to use custom attributes in layout files to initialize the custom view.

三、the key classes

View、ViewParent(interface)、ViewGroup(extends View and implements ViewParent)、ViewRoot

1、View

View is the fundamental class that all of the visible compontents in Android are derived from. It defines a number of callbacks to customize its behavior, like the ability to define size, draw, and save to state.

2、ViewParent(interface)

A ViewParent defines the protocol for any object(including another view) that wants to play the role of a parent to other views. There are two important view parents. Of course, ViewGroup is the key one. In addition to being a ViewParent, a ViewGroup also defines the protocol for a coolection of child views. All layouts like the FrameLayout and LinearLayout in Android SDK extend this class ViewGroup. ViewGroup plays a central role in defining these layouts in XML files and in placing the controls(views) at the right place. A ViewGroup also controls the background and animation of its child views.

3、The other key ViewParent, the ViewRoot is implementation centric and its not a public API. In some release it is called ViewRoot, and in some implementations it is called ViewRoot Implementation and it may be changed in the future to something else. However, this class is important for understanding how drawing is done in Android.

Being a root parent of all views in the activity, the ViewRoot schedules traversals of all the views in order to first lay them out at the right place with the right size; this is called the layout phase. TheViewRoot then traverses the view hierarchy to draw them; this phase is called drawing phase.

四、Layout Phase:Measurement and Layout

The goal of the layout phase is to know the position and size of each view in the view hierarchy owned by a parent such as the VIewRoot. To calculate the position and size of each view, the ViewRoot initiates a layout phase. However, in the layout phase, the view root dose a traversal of only those views that reported or requested a layout change. This conditional measurement is to save resource and improve response time.

The trigger to the layout phase may come from multiple events. One trigger may be the very first time everytihing is being drawn. Or one of the views, while reacting to an event like a click or touch, could report that its size has changed. In such an event, the view that got clicked on calls the method requestLayout(). This call walks up the chain and gets to the root view(ViewRoot). The root view then schedules a layout traversal message ont the main thread's queue.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. JS判断请求来自Android手机还是iPhone手
  2. 整理的Android多种控件步骤
  3. Android 干货文章集锦
  4. Android通过SystemProperties获取build.p
  5. 最新版的Android4.4.2 SDK无法下载解决
  6. Android View的onTouchEvent和OnTouch区
  7. ActionBarImpl can only be used with a
  8. Android(安卓)RecyclerView滚动定位
  9. android 下载 并显示 progressDialog
  10. 【Android】 Android-wifi 直连 wifi dir