Android实现可旋转的ImageView

发布时间:2020-07-29 14:25:02 作者:sly920224
来源:网络 阅读:2947
直接将RefreshProgress添加进xml中当做ImageView就能使用


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();
    //匀速加速器
    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); //显示图像
        //
        m.setRotate(num);
        Bitmap newBitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),m,true);
        BitmapDrawable bd = new BitmapDrawable(newBitmap);
        this.setImageDrawable(bd); //显示新的图像

    }

    //控制动画
    public void Animation(){
        RotateAnimation rotate = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        //默认为0,为-1时一直循环动画
        rotate.setRepeatCount(-1);
        //添加匀速加速器
        rotate.setInterpolator(lir);
        rotate.setDuration(2000);
        rotate.setFillAfter(true);
        this.startAnimation(rotate);
    }

}


推荐阅读:
  1. Android studio 实现圆形ImageView的方法步骤
  2. android activity ImageView全屏设置

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

旋转的imageview age roi

上一篇:关于Python数据分析的小技巧

下一篇:LH乱码转换

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》