Android 仿微信红包动画特效一分钟搞定

简单来说你多在微信中发几个群红包就能有一些思路,但是有些特定的状态需要注意前后端配合。

搞了半个小时TMD没有把视频转换成GIF,直接上照片吧,醉了~

1.支付完成之后会出现第一个图,打开第二个图的时候当前界面是有一个动画效果的,可以微信中发个群红包试试~

无非是图片抖两下,这里将第二张的红包总布局设置Animation

<?xml version="1.0" encoding= "UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <!--设置图片缩放第一次从0.9-1.1倍-->
    <scale
        android:fromXScale="0.9"
        android:toXScale="1.1"
        android:fromYScale="0.9"
        android:toYScale="1.1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="300"
        android:repeatCount="1"
        android:repeatMode="reverse" />
    <!--设置图片缩放第二次从0.9-1倍-->
    <scale
        android:fromXScale="0.9"
        android:toXScale="1"
        android:fromYScale="0.9"
        android:toYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="300"
        android:repeatCount="1"
        android:repeatMode="reverse" />
</set>
然后在Activity中调就ok了

Animation animationLayout = AnimationUtils.loadAnimation(this, R.anim.award_anima);
awardAnimationLayout.setAnimation(animationLayout);

2.点击图二的开的时候,想让这个图片转动,如果你们的UI妹子就给你一张这个图,只能让当前这个图片按照Y轴转动了

定义一个Animation自己去画吧

package shangche.club.geton.view;

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

/**
 * Created by HuoWei on 2017/12/18.
 */

public class AwardRotateAnimation 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(800);
        setInterpolator(new DecelerateInterpolator());
    }

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

AwardRotateAnimation animation = new AwardRotateAnimation();
animation.setRepeatCount(Animation.INFINITE);
openGroupAward.startAnimation(animation);
网络请求结束后跳转到详情时,记得清空View的状态

openGroupAward.clearAnimation();

demo下载地址:http://download.csdn.net/download/android_hv/10166569


猜你喜欢

转载自blog.csdn.net/Android_hv/article/details/78853614