属性动画-波纹扩散WaveView

再次复习了属性动画,以前总是直接拿别人的轮子来用,现在学以致用,想自己搞一下。

先上图

实现思路:3个圆不断的扩大半径,并且增加颜色的透明度。

代码:

public class WaveView extends RelativeLayout {

    private Circle circle1;
    private Circle circle2;
    private Circle circle3;
    private AnimatorSet animatorSet;

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

    public WaveView(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.layout_wave_view, this, true);
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        circle1 = findViewById(R.id.circle1);
        circle2 = findViewById(R.id.circle2);
        circle3 = findViewById(R.id.circle3);
    }



    public void startAnimation() {
        if (animatorSet == null) {
            PropertyValuesHolder radiusHolder = PropertyValuesHolder.ofInt("radius", 100,200);
            PropertyValuesHolder alphaHolder = PropertyValuesHolder.ofInt("color",255, 0);
            ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(circle1,
                    alphaHolder,radiusHolder);
            objectAnimator.setDuration(1500);
            objectAnimator.setRepeatMode(ValueAnimator.RESTART);
            objectAnimator.setRepeatCount(ValueAnimator.INFINITE);

            ObjectAnimator objectAnimator1 = objectAnimator.clone();
            objectAnimator1.setTarget(circle2);
            objectAnimator1.setStartDelay(500);

            ObjectAnimator objectAnimator2 = objectAnimator.clone();
            objectAnimator2.setTarget(circle3);
            objectAnimator2.setStartDelay(1000);

            animatorSet = new AnimatorSet();
            animatorSet.playTogether(objectAnimator, objectAnimator1, objectAnimator2);
        }
        if (!animatorSet.isRunning()) {
            animatorSet.start();
        }
    }

    public void cancelAnimation() {
        if (animatorSet != null) {
            animatorSet.cancel();
        }
    }


}

复制代码

关于Circle的代码,这里就不贴出来了。源码可以直接到github中Clone代码。欢迎star

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值