Android custom 5.0 style progressBar and androidprogressbar

Source: Internet
Author: User

Android custom 5.0 style progressBar and androidprogressbar
Recently, when I used ProgressBar, I thought about how to use Android5.0. :



General idea: 1. Draw circles through Canvas 2. Control the circle animation through Animator
Code: 1. the code for drawing circles is very simple. @ Overrideprotected void onDraw (Canvas canvas) {super. onDraw (canvas); canvas. drawArc (arcRectf, startAngle + incrementAngele, sweepAngle, false, arcPaint); if (animatorSet = null |! AnimatorSet. isRunning () {startAnimation ();}}
Using canvas. draw Arc to draw startAngle is to draw the starting angle. Adding the incrementAngle variable is for better animation control. 2. animation control code: (this is the most important code) private void startAnimation () {if (animatorSet! = Null & animatorSet. isRunning () {animatorSet. cancel (); // cancel the animation} animatorSet = new AnimatorSet (); // set an animation set AnimatorSet = circuAnimator (); // create an animation that runs a circle. play (set); animatorSet. addListener (new AnimatorListener () {private boolean isCancel = false; @ Overridepublic void onAnimationStart (Animator animation) {}@ Overridepublic void onAnimationRepeat (Animator animation) {}@ Ov Erridepublic void onAnimationEnd (Animator animation) {if (! IsCancel) {startAnimation (); // non-stop loop animation }}@ Overridepublic void onAnimationCancel (Animator animation) {isCancel = true ;}}); animatorSet. start () ;}// default animation time: private int DEFULT_DURATION = 660;/***** loop animation */private AnimatorSet circuAnimator () {// from the small circle to the big circle ValueAnimator holdAnimator1 = ValueAnimator. ofFloat (incrementAngele + response, incrementAngele + 115f); updated (new response () {@ Overridepublic void onAnimationUpdate (ValueAnimator animation) {incrementAngele = (float) animation. getAnimatedValue () ;}}); holdAnimator1.setDuration (DEFULT_DURATION); holdAnimator1.setInterpolator (new LinearInterpolator (); ValueAnimator expandAnimator = ValueAnimator. ofFloat (DEFULT_MIN_ANGLE, DEFULT_MAX_ANGLE); expandAnimator. addUpdateListener (new AnimatorUpdateListener () {@ Overridepublic void onAnimationUpdate (ValueAnimator animation) {sweepAngle = (float) animation. getAnimatedValue (); incrementAngele-= sweepAngle; invalidate () ;}}); expandAnimator. setDuration (DEFULT_DURATION); expandAnimator. setInterpolator (new DecelerateInterpolator (2); // from the large circle to the small circle ValueAnimator holdAnimator = ValueAnimator. ofFloat (startAngle, startAngle + 115f); holdAnimator. addUpdateListener (new AnimatorUpdateListener () {@ Overridepublic void onAnimationUpdate (ValueAnimator animation) {startAngle = (float) animation. getAnimatedValue () ;}}); holdAnimator. setDuration (DEFULT_DURATION); holdAnimator. setInterpolator (new LinearInterpolator (); ValueAnimator narrowAnimator = ValueAnimator. ofFloat (DEFULT_MAX_ANGLE, DEFULT_MIN_ANGLE); narrowAnimator. addUpdateListener (new AnimatorUpdateListener () {@ Overridepublic void onAnimationUpdate (ValueAnimator animation) {sweepAngle = (float) animation. getAnimatedValue (); invalidate () ;}}); narrowAnimator. setDuration (DEFULT_DURATION); narrowAnimator. setInterpolator (new DecelerateInterpolator (2); AnimatorSet set = new AnimatorSet (); set. play (holdAnimator1 ). with (expandAnimator); set. play (holdAnimator ). with (narrowAnimator ). after (holdAnimator1); return set ;}
OK. The main idea of this implementation is the animation use of animation. It is very easy to practice the use of an animation. There are no difficulties.
Network Disk source code: http://pan.baidu.com/s/1dD71XlR

Github address: https://github.com/flyme2012/EastTrain


Blog Park address: http://www.cnblogs.com/flyme2012/p/8ec2c75d44f1896aec817ca441aa5b7c.html



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.