问题
android newb here. I got fade out animations to work but not fade in animations. What is wrong with it? This method is called after a fade out method. The way the fade out works is by fading the view out and then making it gone. Doing the opposite in my fadeInLogin method seems not to work. Also I call fadeInLogin with a delay after the fadeOut so I don't think that these animations are interfering with each other although it is possible.
view1.animate()
.alpha(0f)//Fades buttons
.setDuration(5000)
.setListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animation) {
view1.setVisibility(View.GONE);
}
});
Here is my code.
public void fadeInLogin() {
view1 = findViewById(R.id.loginButton);
view1.setVisibility(View.VISIBLE);
view1.animate()
.alpha(1f)
.setDuration(2000)
.setListener(null);
view2 = findViewById(R.id.passwordText);
view2.setVisibility(View.VISIBLE);
view2.animate()
.alpha(1f)
.setDuration(2000)
.setListener(null).start();
view3 = findViewById(R.id.editText);
view3.setVisibility(View.VISIBLE);
view3.animate()
.alpha(1f)
.setDuration(2000)
.setListener(null).start();
view4 = findViewById(R.id.loginTextView);
view4.setVisibility(View.VISIBLE);
view4.animate()
.alpha(1f)
.setDuration(2000)
.setListener(null).start();
view5 = findViewById(R.id.ipText);
view5.setVisibility(View.VISIBLE);
view5.animate()
.alpha(1f)
.setDuration(2000)
.setListener(null).start();
}
回答1:
use this code:
view1 = findViewById(R.id.loginButton);
view1.setVisibility(View.VISIBLE);
view1.setAlpha(0);
view1.animate()
.alpha(1f)
.setDuration(2000)
.setListener(null);
回答2:
You didn't call start
on the view1 animation.
来源:https://stackoverflow.com/questions/27758840/android-fade-in-not-working