前面讲到,自绘控件就是一块显示区域而已,绘制完了之后再想更改界面,就必须使用invalidate方法。
postInvalidate方法和invalidate方法都能够使得界面刷新。
1:我们先看一下postInvalidate方法,里面只有一句,调用postInvalidateDelayed方法:
AttachInfo 是个啥呢?a set of information given to a view when it is attached to its parent window,
dispatchInvalidateDelayed会使用view的ViewRootHandler 发送一条信息到消息队列的末端,处理信息时,调用view的invalidate方法。所以,postInvalidate方法最终会调用invalidate方法。
2:invalidate方法,该方法会使得view树重绘。如果你更改了某些属性值,重绘的时候就会直观的看到。所以,让你的view动起来的level1
方案就是改变属性值然后invalidate,每次改变一点点,就能使view缓慢的动起来。
光说不练家把什,先上效果图:
动态效果就是随着手指的移动,它会跟着你动。支持许多自定义属性,可以满足需要从零到100%选择的所有需求,如音量,满意度等。支持各种自定义
MyStandardView上一个坑里已经介绍过了。
public class MyView_ArcScale extends MyStandardView {
private int smaller;
private int finalHeight;
private int finalWidth;
private float mScale = 0;//degree
private int inCricleColor = Color.BLUE;
private int outArcColor = Color.GREEN;
private int textColor = Color.BLACK;
private float outArcWidth = 20;
private int startDegree = 0;//degree
private float testSize = 15;
private Paint mPaint;
private float halfHeight; //圆心坐标
private float halfWidth;//圆心坐标
public MyView_ArcScale(Context context) {
this(context, null, 0);
}