简体   繁体   English

Android Alpha动画:覆盖初始Alpha值

[英]Android alpha animation: override initial alpha value

Basically I want something to fade-in and then fade-out. 基本上我希望先淡入然后淡出。 Initially it should be invisible, and when the animation is ended, it should also be invisible. 最初,它应该是不可见的,动画结束时,它也应该是不可见的。

targetView.alpha = 0f;

    var aa = AlphaAnimation(0f, 1.0f);
    aa.duration=2000;
    aa.repeatMode = Animation.REVERSE;
    aa.repeatCount = 1;

I have tried the code above, but it did not work. 我已经尝试了上面的代码,但是没有用。 it seems that the alpha animation is multiplying the initial alpha with that animation. 似乎Alpha动画会将初始Alpha与该动画相乘。 So, 0f * 1.0f = 0f = invisible. 因此,0f * 1.0f = 0f =不可见。

After searching for an answer, I have tried this, but it did not work. 在寻找答案之后,我已经尝试过了,但是没有用。

    aa.fillBefore= true;
    aa.fillAfter=true;

How can I make the animation ignore the initial alpha value? 如何使动画忽略初始Alpha值? Is it impossible, and I should change the visibility at the start/end of the animation manually? 这是不可能的,我应该手动更改动画开始/结束时的可见性吗?

Yes you are right about "it seems that the alpha animation is multiplying the initial alpha with that animation. So, 0f * 1.0f = 0f = invisible.". 是的,您是正确的“似乎Alpha动画正在将初始Alpha与该动画相乘。因此,0f * 1.0f = 0f =不可见。”

Just don't use targetView.alpha = 0f; 只是不要使用targetView.alpha = 0f; , use targetView.setVisibility(View.INVISIBLE); ,请使用targetView.setVisibility(View.INVISIBLE); instead. 代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM