@ViewDebug.ExportedProperty的使用
- 原文链接:http://daemon369.github.io/android/2014/06/12/android-viewdebug-exportedproperty/
- http://www.eoeandroid.com/thread-55461-1-1.html;
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.
这个注释可以用来标记域和方法,该域和方法将会被视服务所“转存”,只有不带参数的非空方法才能被这个注释所诠释;
在查看View源码时,但不清楚@ViewDebug.ExportedProperty的用法:
/**
* The view flags hold various views states.
* {@hide}
*/
@ViewDebug.ExportedProperty
int mViewFlags; /**
* The distance in pixels from the left edge of this view's parent
* to the left edge of this view.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "layout")
protected int mLeft;
/**
* The distance in pixels from the left edge of this view's parent
* to the right edge of this view.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "layout")
protected int mRight;
/**
* The distance in pixels from the top edge of this view's parent
* to the top edge of this view.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "layout")
protected int mTop;
/**
* The distance in pixels from the top edge of this view's parent
* to the bottom edge of this view.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "layout")
protected int mBottom; /**
* The offset, in pixels, by which the content of this view is scrolled
* horizontally.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "scrolling")
protected int mScrollX;
/**
* The offset, in pixels, by which the content of this view is scrolled
* vertically.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "scrolling")
protected int mScrollY; /**
* The left padding in pixels, that is the distance in pixels between the
* left edge of this view and the left edge of its content.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "padding")
protected int mPaddingLeft;
/**
* The right padding in pixels, that is the distance in pixels between the
* right edge of this view and the right edge of its content.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "padding")
protected int mPaddingRight;
/**
* The top padding in pixels, that is the distance in pixels between the
* top edge of this view and the top edge of its content.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "padding")
protected int mPaddingTop;
/**
* The bottom padding in pixels, that is the distance in pixels between the
* bottom edge of this view and the bottom edge of its content.
* {@hide}
*/
@ViewDebug.ExportedProperty(category = "padding")
protected int mPaddingBottom; /**
* Briefly describes the view and is primarily used for accessibility support.
*/
private CharSequence mContentDescription; /**
* Cache the paddingRight set by the user to append to the scrollbar's size.
*/
@ViewDebug.ExportedProperty(category = "padding")
int mUserPaddingRight; /**
* Cache the paddingBottom set by the user to append to the scrollbar's size.
*/
@ViewDebug.ExportedProperty(category = "padding")
int mUserPaddingBottom;
使用@ViewDebug.ExportedProperty注解,我们可以在android提供的工具Monitor(或已经废弃的DDMS)中的Hierarchy Viewer中调试View的属性。我们可以直接观察View的某个变量或方法的值,实时观察View的状态变化。
ExprotedProperty注解源码
/**
* 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.
*/
@Target({ ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface ExportedProperty {
/**
* When resolveId is true, and if the annotated field/method return value
* is an int, the value is converted to an Android's resource name.
*
* @return true if the property's value must be transformed into an Android
* resource name, false otherwise
*/
boolean resolveId() default false;
/**
* A mapping can be defined to map int values to specific strings. For
* instance, View.getVisibility() returns 0, 4 or 8. However, these values
* actually mean VISIBLE, INVISIBLE and GONE. A mapping can be used to see
* these human readable values:
*
* <pre>
* @ViewDebug.ExportedProperty(mapping = {
* @ViewDebug.IntToString(from = 0, to = "VISIBLE"),
* @ViewDebug.IntToString(from = 4, to = "INVISIBLE"),
* @ViewDebug.IntToString(from = 8, to = "GONE")
* })
* public int getVisibility() { ...
* <pre>
*
* @return An array of int to String mappings
*
* @see android.view.ViewDebug.IntToString
*/
IntToString[] mapping() default { };
/**
* A mapping can be defined to map array indices to specific strings.
* A mapping can be used to see human readable values for the indices
* of an array:
*
* <pre>
* @ViewDebug.ExportedProperty(indexMapping = {
* @ViewDebug.IntToString(from = 0, to = "INVALID"),
* @ViewDebug.IntToString(from = 1, to = "FIRST"),
* @ViewDebug.IntToString(from = 2, to = "SECOND")
* })
* private int[] mElements;
* <pre>
*
* @return An array of int to String mappings
*
* @see android.view.ViewDebug.IntToString
* @see #mapping()
*/
IntToString[] indexMapping() default { };
/**
* A flags mapping can be defined to map flags encoded in an integer to
* specific strings. A mapping can be used to see human readable values
* for the flags of an integer:
*
* <pre>
* @ViewDebug.ExportedProperty(flagMapping = {
* @ViewDebug.FlagToString(mask = ENABLED_MASK, equals = ENABLED, name = "ENABLED"),
* @ViewDebug.FlagToString(mask = ENABLED_MASK, equals = DISABLED, name = "DISABLED"),
* })
* private int mFlags;
* <pre>
*
* A specified String is output when the following is true:
*
* @return An array of int to String mappings
*/
FlagToString[] flagMapping() default { };
/**
* When deep export is turned on, this property is not dumped. Instead, the
* properties contained in this property are dumped. Each child property
* is prefixed with the name of this property.
*
* @return true if the properties of this property should be dumped
*
* @see #prefix()
*/
boolean deepExport() default false;
/**
* The prefix to use on child properties when deep export is enabled
*
* @return a prefix as a String
*
* @see #deepExport()
*/
String prefix() default "";
/**
* Specifies the category the property falls into, such as measurement,
* layout, drawing, etc.
*
* @return the category as String
*/
String category() default "";
}
使用
下面是@ViewDebug.ExportedProperty注解的部分属性的使用介绍:
1.category
category用来指定属性的类别,例如measurement, layout, drawing等。我们在自定义View中为使用@ViewDebug.ExportedProperty注解的变量或方法指定category:
@ExportedProperty(category = "marquee")
int x = 1;
@Override
@ExportedProperty(category = "marquee")
public boolean isFocused() {
return true;
}
运行程序,在Hierarchy Viewer中查看View的属性如下:
2.resolveId
当resolveId为true时,如果使用注解的变量或方法的值为int数据,那么这个值会被转化为对应的Android资源的名称。
在R.java中找到一个资源ID:
public static final int activity_main=0x7f030000;
使用注解属性resolveId:
@ExportedProperty(category = "marquee", resolveId = true)
int b = 0x7f030000;
结果如下:
3.mapping
mapping可以将int值映射到指定的字符串值,例如View.getVisibility()返回的值是int值,View中使用注解将其映射为字符串,其中0为”VISIBLE”,4为”INVISIBLE”,8为”GONE”。我们重载View.getVisibility()并加上我们自己定制的映射:
@Override
@ViewDebug.ExportedProperty(category = "marquee",
mapping = {
@ViewDebug.IntToString(from = VISIBLE, to = "MARQUEE_VISIBLE"),
@ViewDebug.IntToString(from = INVISIBLE, to = "MARQUEE_INVISIBLE"),
@ViewDebug.IntToString(from = GONE, to = "MARQUEE_GONE")
})
public int getVisibility() {
return super.getVisibility();
}
结果如下:
4.indexMapping
indexMapping可以将数组的序号映射为字符串。
@ExportedProperty(category = "marquee",
indexMapping = {
@ViewDebug.IntToString(from = 0, to = "MARQUEE_FIRST"),
@ViewDebug.IntToString(from = 1, to = "MARQUEE_SECOND"),
@ViewDebug.IntToString(from = 2, to = "MARQUEE_THIRD")
})
int[] elements = new int[] {
111, 222, 333
};
结果如下:
Demo
package com.daemon.demo;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.ViewDebug;
import android.view.ViewDebug.ExportedProperty;
import android.widget.TextView;
public class MarqueeText extends TextView {
public MarqueeText(Context context) {
super(context);
}
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
}
@ExportedProperty(category = "marquee")
int x = 1;
@Override
@ExportedProperty(category = "marquee")
public boolean isFocused() {
return true;
}
@ExportedProperty(category = "marquee", resolveId = true)
int b = 0x7f030000;
@Override
@ViewDebug.ExportedProperty(category = "marquee",
mapping = {
@ViewDebug.IntToString(from = VISIBLE, to = "MARQUEE_VISIBLE"),
@ViewDebug.IntToString(from = INVISIBLE, to = "MARQUEE_INVISIBLE"),
@ViewDebug.IntToString(from = GONE, to = "MARQUEE_GONE")
})
public int getVisibility() {
return super.getVisibility();
}
@ExportedProperty(category = "marquee",
indexMapping = {
@ViewDebug.IntToString(from = 0, to = "MARQUEE_FIRST"),
@ViewDebug.IntToString(from = 1, to = "MARQUEE_SECOND"),
@ViewDebug.IntToString(from = 2, to = "MARQUEE_THIRD")
})
int[] elements = new int[] {
111, 222, 333
};
}
@ViewDebug.ExportedProperty的使用的更多相关文章
- 和我一起看API(一)你所不知道的LinearLayout补充
楼主英语水平差,翻译的不好的话请多多指正,嘿嘿... A Layout that arranges its children in a single column or a single row. T ...
- View Focus的处理过程及ViewGroup的mFocused字段分析
通过上篇的介绍,我们知道在对KeyEvent的处理中有非常重要的一环,那就是KeyEvent在focus view的path上自上而下的分发, 换句话说只有focus的view才有资格参与KeyEve ...
- scrollTo 和 scrollBy
涉及到滑动,就涉及到VIEW,大家都知道,Android的UI界面都是由一个一个的View以及View的派生类组成,View作为基类,而常用的布局里面的各种布局就是它派生出来的ViewGroup的 ...
- 滑动的Button
在介绍SwitchButton之前,先来看一下系统Button是如何实现的.源码如下: @RemoteView public class Button extends TextView { publi ...
- 简单研究Android View绘制二 LayoutParams
2015-07-28 17:23:20 本篇是关于LayoutParams相关 ViewGroup.LayoutParams文档解释如下: LayoutParams are used by views ...
- Android 实现多行文本跑马灯效果
Android TextView 实现跑马灯的效果很简单,只要加三个属性就可以了. android:ellipsize="marquee" android:focusable=&q ...
- Android开发之Theme、Style探索及源码浅析
1 背景 前段时间群里有伙伴问到了关于Android开发中Theme与Style的问题,当然,这类东西在网上随便一搜一大把模板,所以关于怎么用的问题我想这里也就不做太多的说明了,我们这里把重点放在理解 ...
- 向左对齐的Gallery
系统自带的Gallery选中的item总是在组件的中间.但是有些时候我们需要把选中的元素放在左边或者是Gallery一出来就要放在左边.修改Gallery靠左对齐的思路:1.Gellary总是对cen ...
- android 布局之滑动探究 scrollTo 和 scrollBy 方法使用说明
涉及到滑动,就涉及到VIEW,大家都知道,Android的UI界面都是由一个一个的View以及View的派生类组成,View作为基类,而常用的布局里面的各种布局就是它派生出来的ViewGroup的子类 ...
随机推荐
- Win8.1安装Visual Studio 2015提示需要KB2999226
http://www.microsoft.com/zh-cn/download/details.aspx?id=48234 ,下载解压出来就有了,里面包含Vista.Win7.Win8.1三个系统x8 ...
- Windows消息大全(转)
原链接地址: http://www.cnblogs.com/icebutterfly/archive/2011/08/05/2128864.html 表A-1 Windows消息分布 消息范围说 明 ...
- .net网站能走多远
刚写好了学校网站,请大家帮忙测试一下.不知道怎么sql注入,或者DDoS攻击,我也是大四什么都是摸索阶段,不过这个网站 做了好长时间了,现在终于可以上架了,希望大家能指点一二,谢谢! 地址:http: ...
- MongoDB(八)Mongodb——GridFS存储
mongoDB的文档以BSON格式存储,支持二进制的数据类型,当我们把二进制格式的数据直接保存到mongoDB的文档中.但是当文件太大时,例如图片和视频等文件,每个文档的长度是有限的,于是mongoD ...
- stringbuffer和stringbuilder
StringBuffer是线程安全的可变字符序列.长度可变,类型任意,最终都要转换为字符串存储.是一个字符串缓冲区,是一个容器.用于临时存储数据.不过StringBuffer缓冲区内部是由数组来存储的 ...
- AKKA(一)认知AKKA
Akka 是一个用 Scala 编写的库,用于简化编写容错的.高可伸缩性的 Java 和 Scala 的 Actor 模型应用.它已经成功运用在电信行业.系统几乎不会宕机(高可用性 99.999999 ...
- 用Python读写Excel文件(转)
原文:google.com/ncr 虽然天天跟数据打交道,也频繁地使用Excel进行一些简单的数据处理和展示,但长期以来总是小心地避免用Python直接读写Excel文件.通常我都是把数据保存为以TA ...
- jq之ajax以及json数据传递
<html> <head><meta http-equiv="Content-Type" content="text/html; chars ...
- AIX 环境下Telnet返回提示所有端口已经被占用,处理方法
IBM AIX v5.3操作系统环境Telnet返回提示所有端口已经被占用 可以按以下步骤进行检查和处理 1,以下命令检查pty0是否可用 #lsdev -Cl pty0 2,以下命令检查telnet ...
- mxnet实战系列(一)入门与跑mnist数据集
最近在摸mxnet和tensorflow.两个我都搭起来了.tensorflow跑了不少代码,总的来说用得比较顺畅,文档很丰富,api熟悉熟悉写代码没什么问题. 今天把两个平台做了一下对比.同是跑mn ...