Android view lifecycle[转载]
2015-07-17 19:06
706 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a2631388/article/details/84733303
Note: The Android framework is responsible for measuring, laying out and drawing views. You should not call methods that perform these actions on views yourself unless you are actually implementing a ViewGroup.
Android view lifecycle
What is View?
View class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.Using Views
All of the views in a window are arranged in a single tree. You can add views either from code or by specifying a tree of views in one or more XML layout files. There are many specialized subclasses of views that act as controls or are capable of displaying text, images, or other content. Once you have created a tree of views, there are typically a few types of common operations you may wish to perform:- Set properties: for example setting the text of a TextView. The available properties and the methods that set them will vary among the different subclasses of views. Note that properties that are known at build time can be set in the XML layout files.
- Set focus: The framework will handled moving focus in response to user input. To force focus to a specific view, call requestFocus().
- Set up listeners: Views allow clients to set listeners that will be notified when something interesting happens to the view. For example, all views will let you set a listener to be notified when the view gains or loses focus. You can register such a listener using setOnFocusChangeListener(android.view.View.OnFocusChangeListener). Other view subclasses offer more specialized listeners. For example, a Button exposes a listener to notify clients when the button is clicked.
- Set visibility: You can hide or show views using setVisibility(int).
Note: The Android framework is responsible for measuring, laying out and drawing views. You should not call methods that perform these actions on views yourself unless you are actually implementing a ViewGroup.
Implementing a Custom View
To implement a custom view, you will usually begin by providing overrides for some of the standard methods that the framework calls on all views. You do not need to override all of these methods. In fact, you can start by just overriding onDraw(android.graphics.Canvas).Category | Methods | Description |
---|---|---|
Creation | Constructors | There is a form of the constructor that are called when the view is created from code and a form that is called when the view is inflated from a layout file. The second form should parse and apply any attributes defined in the layout file. |
|
Called after a view and all of its children has been inflated from XML. | |
Layout |
|
Called to determine the size requirements for this view and all of its children. |
|
Called when this view should assign a size and position to all of its children. | |
|
Called when the size of this view has changed. | |
Drawing |
|
Called when the view should render its content. |
Event processing |
|
Called when a new hardware key event occurs. |
|
Called when a hardware key up event occurs. | |
|
Called when a trackball motion event occurs. | |
|
Called when a touch screen motion event occurs. | |
Focus |
|
Called when the view gains or loses focus. |
|
Called when the window containing the view gains or loses focus. | |
Attaching |
|
Called when the view is attached to a window. |
|
Called when the view is detached from its window. | |
|
Called when the visibility of the window containing the view has changed. |
View lifecycle
出处:http://ndquangr.blogspot.com/2013/04/android-view-lifecycle.html
相关文章推荐
- android ViewTreeObserver详细讲解 (转载)
- 发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方案(转载http://daydayup1989.iteye.com/blog/784831)
- Android 利用addView 让Activity 动态加入多个View 物件(转载)
- 转载:【译】Android: 自定义View
- Android界面View及ViewGroup学习 《转载》
- Android ViewGroup实现页面滑动效果并实现不同的动画效果(转载)
- Android ListView与RecyclerView对比浅析--缓存机制<转载自http://dev.qq.com/topic/5811d3e3ab10c62013697408>
- Android---3种方式限制EditView输入字数(转载)
- android大扫盲之SurfaceView,SurfaceHolder,SurfaceHolder.CallBack.你hold住了吗【转载】
- 【转载】Android---3种方式限制EditView输入字数
- Android ViewGroup实现页面滑动效果并实现不同的动画效果(转载)
- Android View类开源项目【转载】
- Android的View和ViewGroup分析(转载)
- 转载----android应用程序中获取view的位置
- Android---3种方式限制EditView输入字数(转载)
- Android 利用ViewPager、Fragment、PagerTabStrip实现多页面滑动效果(转载)
- Android ImageView 总结【转载】
- 转载 android之ImageView
- Android View 的一些属性(复制转载过来的,做个笔记)
- 【转载】 android 圆角圆形图片ShapedImageView不到100行代码