ViewDebug

来源:互联网 发布:linux etc passwd 编辑:程序博客网 时间:2024/06/06 02:07

在看LinearLayout 的源码的时候,看到这样一个:ViewDebug

@ViewDebug.ExportedProperty
private boolean mBaselineAligned = true;

它通常写在一个属性或者一个方面的上面,我知道这是一个注解,但是到底起什么作用呢?不知道。。。

ViewDebug.ExportedProperty在Doc里面是这样解释的:

This annotation can be used to mark fields and methods to be dumped by the view server. Only non-void methods with no arguments can be annotated by this annotation.

继续看下ViewDebug是干什么用的?

类前面的注释:Various debugging/tracing tools related to {@link View} and the view hierarchy.

我的翻译:关于view和不同层次View的调试和追踪的工具。

说白了,就是调试用的,或者追踪view的路径用的。这个类大量的使用了注解,里面定义了很多注解来供本类使用。里面的很多方法,暂时还没细看,待看。。。

 

 public void invalidate() {
        if (ViewDebug.TRACE_HIERARCHY) {
            ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE);
        }

在View的这个方法中,使用了ViewDebug,我看了源码后,总算有点新的理解了。

public enum HierarchyTraceType {
        INVALIDATE,
        INVALIDATE_CHILD,
        INVALIDATE_CHILD_IN_PARENT,
        REQUEST_LAYOUT,
        ON_LAYOUT,
        ON_MEASURE,
        DRAW,
        BUILD_CACHE
    }

这个枚举类型,就是View在绘制过程中的不同状态,我们可以ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE);
这样去查看某个View当前的绘制状态。

 

 

原创粉丝点击