Animation之闪烁的星星

CSDN早就有了,但是以前都没时间写。

现在有时间写了一个关于animation的demo。

一个简单的demo,一些关于animation的属性自己网上查一下吧!


好了先看看下面的这个效果图吧!如果是你需要的效果。自己拿去玩玩吧...

Animation之闪烁的星星_第1张图片


看了图片,那我们现在来看看代码吧!

很简单:

public void propertyAnimation(View view){
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, "rotation", 0, 45, 0);
    objectAnimator.setRepeatMode(ValueAnimator.REVERSE);//动画倒转播放
    objectAnimator.setDuration(2500);//播放动画的时间mm
    objectAnimator.setRepeatCount(-1);//动画次数(-1,无限次)
    ObjectAnimator objectAnimatoralpha = objectAnimator.ofFloat(view, "alpha", 1, 0.4f, 1);
    objectAnimatoralpha.setRepeatMode(ValueAnimator.REVERSE);
    objectAnimatoralpha.setDuration(2300);
    objectAnimatoralpha.setRepeatCount(-1);
    ObjectAnimator animatorscaleX = objectAnimator.ofFloat(view, "scaleX", 1.0f, 0.8f);
    animatorscaleX.setRepeatMode(ValueAnimator.REVERSE);
    animatorscaleX.setDuration(2000);
    animatorscaleX.setRepeatCount(-1);
    ObjectAnimator animatorscaleY = objectAnimator.ofFloat(view, "scaleY", 1.0f, 0.8f);
    animatorscaleY.setRepeatMode(ValueAnimator.REVERSE);
    animatorscaleY.setDuration(2000);
    animatorscaleY.setRepeatCount(-1);
    ObjectAnimator animatortranslationX = objectAnimator.ofFloat(view, "translationX", 0.0f, 100);
    animatorscaleY.setRepeatMode(ValueAnimator.REVERSE);
    animatorscaleY.setDuration(10000);
    animatorscaleY.setRepeatCount(-1);
    ObjectAnimator animatortranslationY = objectAnimator.ofFloat(view, "translationY", 0.0f, 90);
    animatorscaleY.setRepeatMode(ValueAnimator.REVERSE);
    animatorscaleY.setDuration(10000);
    animatorscaleY.setRepeatCount(-1);

    AnimatorSet animationSet = new AnimatorSet();
    animationSet.play(objectAnimator).with(objectAnimatoralpha);
    //这里执行动画的循序要注意了,不然效果就天差地别了
    animationSet.play(animatorscaleY).with(animatorscaleX);
    animationSet.play(animatortranslationX).with(animatortranslationY);
    animationSet.start();

}
 
  
这是一段属性动画

你可能感兴趣的:(android,安卓,android动画,android闪烁的星星)