Rotating ImageView for Android
You can directly add RefreshProgress to xml as ImageView to use package com. example. administrator. superrefresh; import android. content. context; import android. graphics. bitmap; import android. graphics. matrix; import android. graphics. drawable. bitmapDrawable; import android. util. attributeSet; import android. view. animation. animation; import android. view. animation. linearInterpolator; import android. view. animation. rotateAnimation; import android. widget. imageView;/*** Created by SLY on 2015/9/6. */public class RefreshProgress extends ImageView {private Matrix m = new Matrix (); // accelerator private LinearInterpolator lir = new LinearInterpolator (); public RefreshProgress (Context context) {super (context);} public RefreshProgress (Context context, AttributeSet attrs) {super (context, attrs);} public void changeAnimation (int num) {m. reset (); // Bitmap bitmap = (BitmapDrawable) getResources (). getDrawable (R. drawable. loading_rotate )). getBitmap (); this. setImageBitmap (bitmap); // display the image // m. setRotate (num); Bitmap newBitmap = Bitmap. createBitmap (bitmap, 0, 0, bitmap. getWidth (), bitmap. getHeight (), m, true); BitmapDrawable bd = new BitmapDrawable (newBitmap); this. setImageDrawable (bd); // display new images} // control the Animation public void Animation () {RotateAnimation rotate = new RotateAnimation (0,720, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); // The default value is 0. If it is-1, the animation is continuously rotated. setRepeatCount (-1); // Add the constant speed accelerator rotate. setInterpolator (lir); rotate. setDuration (2000); rotate. setFillAfter (true); this. startAnimation (rotate );}}