1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| * Created by Jack on 2015/10/16. */ public class BallClipRotateIndicator extends Indicator {
float scaleFloat=1,degrees;
@Override public void draw(Canvas canvas, Paint paint) { paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3);
float circleSpacing=12; float x = (getWidth()) / 2; float y=(getHeight()) / 2; canvas.translate(x, y); canvas.scale(scaleFloat, scaleFloat); canvas.rotate(degrees); RectF rectF=new RectF(-x+circleSpacing,-y+circleSpacing,0+x-circleSpacing,0+y-circleSpacing); canvas.drawArc(rectF, -45, 270, false, paint);//画有一段弧形 }
@Override public ArrayList<ValueAnimator> onCreateAnimators() { ArrayList<ValueAnimator> animators=new ArrayList<>(); ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.6f,0.5f,1); scaleAnim.setDuration(750); scaleAnim.setRepeatCount(-1); addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloat = (float) animation.getAnimatedValue(); postInvalidate(); } }); ValueAnimator rotateAnim=ValueAnimator.ofFloat(0,180,360); rotateAnim.setDuration(750); rotateAnim.setRepeatCount(-1); addUpdateListener(rotateAnim,new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { degrees = (float) animation.getAnimatedValue(); postInvalidate(); } }); animators.add(scaleAnim); animators.add(rotateAnim); return animators; } }
|