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).
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. |
相关推荐
Flutter的flutter_plugin_android_lifecycle插件是一个Flutter插件,用于访问Android Lifecycle objects。它可以帮助其他Flutter插件在Android上更好地集成。 要使用flutter_plugin_android_lifecycle插件,需要将...
androidx-lifecycle-common-2.1.0.jar
androidx-lifecycle-livedata-core-2.0.0.aar
androidx-lifecycle-livedata-2.0.0.aar
android-lifecycle, Android Activity/fragment 生命周期的图表 完整的Android fragment & Activity 生命周期尝试了解各种各样的片段之后,我做了一些研究并将完整的Android Activity/fragment 生命周期结合起来。...
androidx lifecycle 2.3.0 资源包
本文将深入探讨Android中的生命周期(LifeCycle)机制,以及如何利用相关工具进行调试和优化。 Android Activity的生命周期是其从创建到销毁的一系列状态变化。主要包含以下几个关键状态: 1. **初始化态...
AndroidX:androidx.lifecycle:lifecycle-common-java8:2.0.0-rc01 旧版本包:android.arch.lifecycle:compiler AndroidX:androidx.lifecycle:lifecycle-compiler:2.0.0-rc01 旧版本包:android.arch.lifecycle:...
Android官方activity-lifecycle生命周期例子,参考网页: http://developer.android.com/training/basics/activity-lifecycle/index.html 方便了解Activity生命周期,提供了非常形象的说明。生动讲解。可以结合官网...
很早就听说了Google的Lifecycle组件,因为项目没有使用过,所以并没有过多的接触。不过最近看到了一篇文章,其中的一条评论提到了LiveData。恰巧这两天工作内容不多,所以赶紧研究一波! 不过在看LiveData之前,我...
androidx-lifecycle-runtime-2.1.0.aar
发生于编译时:错误: 程序包androidx.lifecycle不存在 先贴一段报错log,让你更加准确的匹配问题所在,对症下药,药,切克闹。 D:\study\flutter\flutter\.pub-cache\hosted\pub.flutter-io....
Android生命周期演示展示android活动生命周期的android应用演示。 有两个活动, MainActivity.java和secondActivity.java 。 使用logcat和log类,当两个活动中的每个回调都被调用时,此应用向用户显示。 这两个活动...
Android框架组件Lifecycle的使用详解 Android框架组件Lifecycle是Google推出的一系列框架组件之一,主要用于感知Activity和Fragment的生命周期。Lifecycle组件能够解决生命周期方法变臃肿的问题,使代码更加优雅。 ...
androidx-lifecycle-viewmodel.aar
本框架 是对 RXJAVA2 Retrofit RxBus OkHttp 的架构的封装 达成目标:链式调用,简单明了 1.支持 主流的Http 请求 2.支持 多文件上传 监听进度 3.支持 大文件下载 监听进度
"Android Fragment Lifecycle"这一主题主要涉及Fragment从创建到销毁的各个阶段及其相关的回调方法。 Fragment的生命周期可以分为几个关键阶段: 1. **添加/初始化阶段**: - `onAttach()`:Fragment与Activity...
在iOS开发中,View Controller(视图控制器)生命周期是开发者必须深入理解的重要概念。View Controller是Apple提供的一个关键组件,用于管理屏幕上的UI元素和用户交互。本文将详细阐述iOS中View Controller生命周期...