自定义控件精进

#1024程序员节#

学习 Android 的 View 体系前在心里先来个灵魂三问,然后逐一分析:

  1. 什么是View?
  2. 为什么要学View?
  3. 该怎么学View?

对于Android的View体系学习,归根结底是View.java和ViewGroup.java,我们直接看这两个类的注释(android.view.View.java):

This 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.

// 往上再没有父类,实现了三个接口
public class View implements Drawable.Callback, KeyEvent.Callback,
        AccessibilityEventSource {
        ...// 3万多行代码,不要从头看,会晕,需要掌握方式方法来学

大致意思如下:
该类代表用户界面组件的基本构建块。 一个 View 在屏幕上占据一个矩形区域,负责绘制和事件处理。 View 是小部件的基类,用于创建交互式 UI 组件(按钮、文本字段等)。 ViewGroup 子类是布局的基类,布局是包含其他 View(或其他 ViewGroup)并定义其布局属性的不可见容器。

再看ViewGroup.java(android.view.ViewGroup.java)

A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers. This class also defines the ViewGroup.LayoutParams class which serves as the base class for layouts parameters.

// 继承自View并实现了两个接口
public abstract class ViewGroup extends View implements ViewParent, ViewManager {
	...// 9千多行代码

ViewGroup的注释为:
ViewGroup 是一个特殊的视图,可以包含其他视图(称为子视图)。视图组是布局和视图容器的基类。 该类还定义了ViewGroup.LayoutParams 类,该类用作布局参数的基类。

有了是什么,就有了一个初步的认识,接下来思考为什么要学?

  • 能更好的掌握系统控件的使用;
  • 实现系统未提供的自定义控件;
  • 解决项目中遇到的实际问题;
  • 。。。

关于如何学习,我这里初步做了个提纲,近期会逐一填补:

学习完控件View的内容,最后再补充一个动画。

Created with Raphaël 2.3.0 开始 构造函数// 初始化 onMeasure()// 测量大小 onSizeChanged()// 确定大小 onLayout()// 确定子view布局 视图改变// 用户操作或自己改变 结束
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小山研磨代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值