Android淡入不起作用 [英] Android fade in not working

查看:112
本文介绍了Android淡入不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

android newb在这里。我可以淡出动画,但不能淡入动画。怎么了在淡出方法之后调用此方法。淡出的工作方式是使视图淡出然后消失。在我的fadeInLogin方法中执行相反的操作似乎无效。我也可以在fadeOut之后延迟调用fadeInLogin,所以我认为这些动画虽然可能发生,但不会互相干扰。

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

                }
            }); 

这是我的代码。

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


            }


推荐答案

使用此代码:

 view1 = findViewById(R.id.loginButton);
 view1.setVisibility(View.VISIBLE);
 view1.setAlpha(0);
 view1.animate()
        .alpha(1f)
        .setDuration(2000)
        .setListener(null);

这篇关于Android淡入不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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