简单的实现微信领取红包界面,按钮旋转动画效果。

最近在做一下项目,是领取红包的,我们这里仿照的微信的红包领取界面,点击按钮之后立体旋转,然后打开红包:


我这里用的是旋转动画,然后沿着Y轴去旋转,说了这么多,下面来看一下效果:



现在清楚多了把 ,我用自定义了一个动画,找到控件的中心,然后让中心沿着Y轴去旋转,不多说了看代码吧:

package com.lixuce.myapplication;

import android.content.Context;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Transformation;

/**
 * Created by lixuce on 2017/4/10.
 */

public class MyAnimation extends Animation {
    int centerX, centerY;
    Camera camera = new Camera();

    
    @Override
    public void initialize(int width, int height, int parentWidth,
                           int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        //获取中心点坐标
        centerX = width/ 2;
        centerY = height / 2;
        //动画执行时间  自行定义
        setDuration(2500L);
        setInterpolator(new AccelerateInterpolator());
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        final Matrix matrix = t.getMatrix();
        camera.save();
        //中心是绕Y轴旋转  这里可以自行设置X轴 Y轴 Z轴
        camera.rotateY(1080 * interpolatedTime);
        //把我们的摄像头加在变换矩阵上
        camera.getMatrix(matrix);
        //设置翻转中心点
        matrix.preTranslate(-centerX, -centerY);
        matrix.postTranslate(centerX, centerY);
        camera.restore();
    }
}

用法:

MyAnimation mAnimation = new MyAnimation();

     
                ivxuanzhuan.startAnimation(mAnimation);
这样是不是很容易就实现了动画了效果了。希望能对大家有所帮助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值