当前位置:   article > 正文

java fadein_用Java淡入淡出Android动画

android animation fadein

弄清楚我自己的问题。该解决方案最终基于插值器。

Animation fadeIn = new AlphaAnimation(0, 1);

fadeIn.setInterpolator(new DecelerateInterpolator()); //add this

fadeIn.setDuration(1000);

Animation fadeOut = new AlphaAnimation(1, 0);

fadeOut.setInterpolator(new AccelerateInterpolator()); //and this

fadeOut.setStartOffset(1000);

fadeOut.setDuration(1000);

AnimationSet animation = new AnimationSet(false); //change to false

animation.addAnimation(fadeIn);

animation.addAnimation(fadeOut);

this.setAnimation(animation);

如果您使用的是Kotlin

val fadeIn = AlphaAnimation(0f, 1f)

fadeIn.interpolator = DecelerateInterpolator() //add this

fadeIn.duration = 1000

val fadeOut = AlphaAnimation(1f, 0f)

fadeOut.interpolator = AccelerateInterpolator() //and this

fadeOut.startOffset = 1000

fadeOut.duration = 1000

val animation = AnimationSet(false) //change to false

animation.addAnimation(fadeIn)

animation.addAnimation(fadeOut)

this.setAnimation(animation)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/660218
推荐阅读
相关标签
  

闽ICP备14008679号