淡入淡出的Andr​​oid动画在Java中 [英] Fade In Fade Out Android Animation in Java

查看:96
本文介绍了淡入淡出的Andr​​oid动画在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个花费1000毫秒衰落,然后1000ms的淡出了ImageView的的2秒的动画。

I want to have a 2 second animation of an ImageView that spends 1000ms fading in and then 1000ms fading out.

下面是我到目前为止在我的ImageView的构造函数:

Here's what I have so far in my ImageView constructor:

Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setDuration(1000);

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);

AnimationSet animation = new AnimationSet(true);
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
this.setAnimation(animation);

当我运行动画的没有的显示出来。然而,当我删除了阿尔法的动画之一,行为正常工作。

When I run that animation, nothing shows up. However, when I remove one of the alpha animations, the behavior works as expected.

东西:

  • setFillBefore setFillAfter 的每一个可以想到的组合,而 setFillEnabled
  • 添加 LinearInterpolator AnimationSet
  • Every conceivable combination of setFillBefore, setFillAfter, and setFillEnabled.
  • Adding a LinearInterpolator to the AnimationSet.

推荐答案

想通了我自己的问题。最终的解决方案是基于在插补器。

Figured out my own problem. The solution ended up being based in interpolators.

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);

这篇关于淡入淡出的Andr​​oid动画在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆