繁体   English   中英

TextView不断弹出

[英]TextView keeps popping up

我有一个活动,其中出现了TextView,然后消失了。 但是,每次淡出时,它都会弹出。

wtext.setText("");

但是然后我的文本消失了而没有消失(消失后)。 有谁知道如何解决这个问题? 谢谢! 亲切的问候。

这是我的代码:

public class SplashScreen extends Activity {



protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    Handler handler = new Handler();

    final TextView wtext = (TextView) (findViewById(R.id.wtext));

    Animation animation = AnimationUtils.loadAnimation(this, R.anim.abc_fade_in);
    wtext.startAnimation(animation);

    Runnable task = new Runnable() {

                @Override
                public void run() {
                    Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.abc_fade_out);
                    wtext.startAnimation(animation1);
                    wtext.setText("");
                }
    };
    handler.postDelayed(task, 5000);

}

如果您希望动画制作完成后发生某些事情(在这种情况下,隐藏文本视图),则必须使用AnimationListener

Animation.AnimationListener myListener = new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                wtext.setVisibility(View.INVISIBLE);
            }

        };
animation1.setAnimationListener(myListener);

您可以使用ViewPropertyAnimator ,它会更改视图的实际属性,而不仅仅是外观,因此在动画完成后它不会跳回到原始状态。

wtext.animate().alpha(0);

您可以尝试在元素上将fillAfter标志设置为true :动画完成后,它将对其应用最终的转换。

暂无
暂无

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

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