资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Android实现可旋转的ImageView

直接将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);
    }

}

文章名称:Android实现可旋转的ImageView
分享路径:http://cdkjz.cn/article/ppjsgp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220