Android开发红包动画效果

195 阅读1分钟
Android开发红包动画效果

左右晃动的红包动画效果,吸引用户点击

一、思路:

使用View的动画效果,自定义ImageView

二、效果图:

在这里插入图片描述

三、关键代码:
public class MyImageView extends AppCompatImageView {

    private boolean mAnimating;
    private RotateAnimation mRotateAnimation;


    public MyImageView(Context context) {
        this(context, null);
    }

    public MyImageView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mRotateAnimation = new RotateAnimation(-30f, 30f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.2f);
        mRotateAnimation.setDuration(300);
        mRotateAnimation.setRepeatCount(-1);
        mRotateAnimation.setRepeatMode(Animation.REVERSE);
    }
四、项目demo源码结构图:

在这里插入图片描述
有问题或者需要完整源码的私信我