1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 简单的实现微信领取红包界面 按钮旋转动画效果。

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

时间:2024-01-26 09:18:21

相关推荐

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

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

我这里用的是旋转动画,然后沿着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 /4/10.*/public class MyAnimation extends Animation {int centerX, centerY;Camera camera = new Camera();@Overridepublic 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());}@Overrideprotected 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);

这样是不是很容易就实现了动画了效果了。希望能对大家有所帮助

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。