博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
以一点为中心旋转动画实现,摇摆动画
阅读量:4678 次
发布时间:2019-06-09

本文共 1580 字,大约阅读时间需要 5 分钟。

// 获取自定义动画实例CustomRotateAnim rotateAnim = CustomRotateAnim.getCustomRotateAnim();// 一次动画执行0.2秒rotateAnim.setDuration(200);// 设置为循环播放rotateAnim.setRepeatCount(4);// 设置为匀速rotateAnim.setInterpolator(new LinearInterpolator());// 开始播放动画redlayout.startAnimation(rotateAnim);//动画状态监听rotateAnim.setAnimationListener(new Animation.AnimationListener() {    @Override    public void onAnimationStart(Animation animation) {//开始    }    @Override    public void onAnimationEnd(Animation animation) {//结束    }    @Override    public void onAnimationRepeat(Animation animation) {    }});

 

自定义类:
public class CustomRotateAnim extends Animation {    /** 控件宽 */    private int mWidth;    /** 控件高 */    private int mHeight;    /** 实例 */    private static CustomRotateAnim rotateAnim;    /**     * 获取动画实例     * @return 实例     */    public static CustomRotateAnim getCustomRotateAnim() {        if (null == rotateAnim) {            rotateAnim = new CustomRotateAnim();        }        return rotateAnim;    }    @Override    public void initialize(int width, int height, int parentWidth, int parentHeight) {        this.mWidth = width;        this.mHeight = height;        super.initialize(width, height, parentWidth, parentHeight);    }    @Override    protected void applyTransformation(float interpolatedTime, Transformation t) {        // 左右摇摆PI*2)*N控制摇摆幅度(N越小幅度越小),后面两个参数控制旋转中心点的位置        t.getMatrix().setRotate((float)(Math.sin(interpolatedTime*Math.PI*2)*5), mWidth/2, mHeight/2);        super.applyTransformation(interpolatedTime, t);    }}

 

转载于:https://www.cnblogs.com/lucky-zhu/p/6215174.html

你可能感兴趣的文章
Cyclone V 与 Avalon-MM资料整理——DE1-SOC学习笔记(1)
查看>>
异常:This application has no explicit mapping for /error, so you are seeing this as a fallback.
查看>>
Flask-SQLAlchemy
查看>>
C# - Generics
查看>>
.NET LINQ 转换数据类型
查看>>
[LGP2791] 幼儿园篮球题
查看>>
[linux-内核][转]内核日志及printk结构浅析
查看>>
SWMM[Storm Water Management Model]模型代码编译调试环境设置
查看>>
s11 day Linux 和nginx 部署
查看>>
程序猿的爱情-2012-01-22
查看>>
CentOS7.2 安装iptables
查看>>
网络是怎样连接的—1.浏览器生成消息
查看>>
codevs1430 素数判定
查看>>
2017年6月2号课堂笔记
查看>>
github
查看>>
poj1015【DP.......无奈了】
查看>>
C#性能优化的一些技巧
查看>>
PAT 甲级 1024 Palindromic Number
查看>>
信息安全经典书籍
查看>>
ios坐标位置转换
查看>>