[Android] custom arbitrary onDraw-based animation (not just PAN/rotate/zoom/alpha ),!,
Ideas:
1. Time-based display ing. For example, if the degrees are specified, the arc is displayed, and the time sequence is added, the arc animation effect can be achieved.
2. specify the time sequence. One frame for animation Rendering
Solution 1,Based on ObjectAnimator. During animation operation, the set function corresponding to degree is called (based on radiation), that is, setDegree.
ObjectAnimator ani = ObjectAnimator. ofInt (myView, "degree", 0,300 );
Ani. start ();
Note: 1> after mixing, setDegree will be mixed by default, resulting in no function found. Therefore, this mechanism will become invalid after mixing. Solution: 1. prevent this section of code from being mixed in proguard (the specific method is Baidu) 2. Use method 2
2> ObjectAnimator is supported only after 3.0. You can use the NineOldAndroids library to achieve the same effect.
Solution 2,Still Based on ObjectAnimator. But based on callback, this method does not use reflection, so it is still OK during mixed encoding.
ObjectAnimator ani = ObjectAnimator. ofInt (myView, new Prop (), 0,300 );
Ani. start ();
class Prop extends Property<View, Integer> {public Prop() {// TODO Auto-generated constructor stubsuper(Integer.class, "kk");}@Overridepublic void set(View object, Integer value) {// TODO Auto-generated method stub((MyView1)object).setDegree(value);}@Overridepublic Integer get(View object) {// TODO Auto-generated method stubreturn null;}};
Solution 3,Use animation to provide time series. InterpolatedTime is 0 ~ 1, that is, the percentage of time.
Animation ani=new Animation() {@Overrideprotected void applyTransformation(float interpolatedTime,Transformation t) {// TODO Auto-generated method stubmyView.setDegree((int)(interpolatedTime*300f));}};ani.setDuration(3000);myView.startAnimation(ani);
// ================================================ ============================================
Custom view. setDegress can change the arc angle:
private class MyView1 extends ImageView {public int degree = 0;public MyView1(Context ct) {// TODO Auto-generated constructor stubsuper(ct);}@Overrideprotected void onDraw(Canvas canvas) {// TODO Auto-generated method stubsuper.onDraw(canvas);Rect r = new Rect();getLocalVisibleRect(r);canvas.drawArc(new RectF(r), 0, degree, true, pt);}public void setDegree(int degree) {this.degree = degree;invalidate();}}
Effect: