Android自定义View之数字自动增长
第一次写博文,请多指教,有何问题及改进建议都可以告诉我-.-
Idea来自金山词霸App的单词计数,下面先放图
如上图,就是,下面开始进入自定义View
自定义View步骤
- 自定义属性
- 生成构造方法
- onMeasure(可选)
- onSizeChanged(可选)
- onLayout(可选)
- onDraw
我这里只重写了onSizeChanged,onMeasure和onLayout没有重写
1.自定义属性
values里面新建attrs
<resources>
<declare-styleable name="AutoNumberView">
//变化速度
<attr name="auto_speed" format="integer"/>
//边框颜色
<attr name="stroke_color" format="color"/>
//数字颜色
<attr name="text_color" format="color"/>
</declare-styleable>
</resources>
2.生成构造方法
public AutoNumberView(Context context) {
super(context);
}
public AutoNumberView(Context context, @Nullable AttributeSet attrs)