TextView、Button、EditText

来源:互联网 发布:小米网络助手apk通用版 编辑:程序博客网 时间:2024/06/09 22:46

 

今天继续我的源码学习。

 

TextView:实现了ViewTreeObserver.OnPreDrawListener这个接口,又看了下,ViewTreeObserver这个类的解释如下:

A view tree observer is used to register listeners that can be notified of global changes in the view tree. Such global events include, but are not limited to, layout of the whole tree, beginning of the drawing pass, touch mode change.... A ViewTreeObserver should never be instantiated by applications as it is provided by the views hierarchy. Refer toandroid.view.View.getViewTreeObserver() for more information.

我的解释:用于注册一个监听器,以便知道所有的view树的改变。例如全局事件,但是不仅仅是全局事件,绘制事件、触摸事件......

有3个构造函数,整个类中代码量很大,这也就是为什么后来的Button和EditText里面的代码极少的原因。里面有几个需要注意的东西,比如:

ColorStateList

onDraw()

debug():特别提下这个方法,里面是对View的一个trace,就是一个路径的分析,就是打印出当前View的一些数据

Spannable:这个是一个接口,注意涉及到一些点击事件,比如一段文字,中间有需要点击的内容,就使用这个来处理,没有真正使用过,但是见过;

Editable:和编辑内容相关的类

TextUtils.TruncateAt:这个类主要处理当一段文字不能完全显示在控件上时的处理策略,是自动换行,还是跑马灯效果,还是从开头截取等;

public enum TruncateAt {
        START,
        MIDDLE,
        END,
        MARQUEE,
    }

 

 Button:

button里面东西比较少,只有3个构造函数,别无其他,暂且不讲;

 

EditText:

这个里面内容也不多,比Button里多的就是几个关于selection和editable的方法。

 

原创粉丝点击