Android fade in not working

痞子三分冷 提交于 2019-12-10 22:27:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!