让一个图片闪烁/左右/上下摇摆

//闪烁

AlphaAnimation alphaAnimation1 = new AlphaAnimation(0.1f, 1.0f);    
alphaAnimation1.setDuration(1000);    
alphaAnimation1.setRepeatCount(Animation.INFINITE);    
alphaAnimation1.setRepeatMode(Animation.REVERSE);    
iv.setAnimation(alphaAnimation1);    
alphaAnimation1.start();

alphaAnimation1.setRepeatCount(Animation.INFINITE); 表示重复多次。 也可以设定具体重复的次数,比如alphaAnimation1.setRepeatCount(5);
alphaAnimation1.setRepeatMode(Animation.REVERSE);表示动画结束后,反过来再执行。 该方法有两种值, RESTART 和 REVERSE。 RESTART表示从头开始,REVERSE表示从末尾倒播

//左右摇摆

TranslateAnimation alphaAnimation2 = new TranslateAnimation(150f, 350f, 50, 50);    
alphaAnimation2.setDuration(1000);    
alphaAnimation2.setRepeatCount(Animation.INFINITE);    
alphaAnimation2.setRepeatMode(Animation.REVERSE);    
iv.setAnimation(alphaAnimation2);    
alphaAnimation2.start();    

//捕鱼图标上下

TranslateAnimation alphaAnimation2 = new TranslateAnimation(0, 0, 0, 25);
alphaAnimation2.setDuration(1000);
alphaAnimation2.setRepeatCount(Animation.INFINITE);
alphaAnimation2.setRepeatMode(Animation.REVERSE);
binding.ivMeFish.setAnimation(alphaAnimation2);
alphaAnimation2.start();
    原文作者:奔跑的图腾
    原文地址: https://www.jianshu.com/p/847ab42520f9
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞