Rotating ImageView for Android

Source: Internet
Author: User

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 );}}

 

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.