找到你要的答案

Q:Animating Button alpha to 0 and the 1 after a delay does not work

Q:动画按钮,α0和1延迟后不工作

I'm new to android development and ran into an issue when trying to fade a button out and then back in. In my app i'm using

 myButton.animate().alpha(0f).duration(200) 

to fade a button and after some other interaction with ui elements i'm doing

 myButton.animate().alpha(1f).duration(200) 

and this works fine. What i want to do now is fade the button out and then back in almost immediately so i tried:

 myButton.animate().alpha(0f).duration(200)
 myButton.animate().alpha(1f).duration(200).startDelay(300)

Unfortunately this two line do not seem to do anything. The button does not change alpa at all and stays visible throughout. Can anyone please explain what's happening? Does it have something to do with animations being transient?

我是新的Android开发和陷入一个问题时,试图淡出按钮,然后回到。在我的应用程序我使用

 myButton.animate().alpha(0f).duration(200) 

淡入淡出按钮和其他一些与UI元素的交互

 myButton.animate().alpha(1f).duration(200) 

这个作品很好。我现在想做的是淡出按钮,然后立即回来,所以我尝试:

 myButton.animate().alpha(0f).duration(200)
 myButton.animate().alpha(1f).duration(200).startDelay(300)

不幸的是这两行似乎没有做任何事情。按钮不改变公司在所有和保持可见整个。谁能解释发生了什么事?它与动画是短暂的有关吗?

answer1: 回答1:

You should use withEndAction instead of just listing the commands one after another.

myButton.animate().setDuration(200).alpha(0).withEndAction(new Runnable() {
            @Override
            public void run() {
                myButton.animate().setDuration(200).alpha(1f).start();
            }
        }).start();

你应该使用withendaction代替刚刚上市的命令一个接一个。

myButton.animate().setDuration(200).alpha(0).withEndAction(new Runnable() {
            @Override
            public void run() {
                myButton.animate().setDuration(200).alpha(1f).start();
            }
        }).start();
android