如何动画淡出和淡入TextView的同时改变文本 [英] How to animate a FadeOut and FadeIn while textView changed text

查看:914
本文介绍了如何动画淡出和淡入TextView的同时改变文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在changeText动画一个TextView
但始终只看到一个动画的方向,我看到的只是淡出

i try to animate a TextView on a changeText But always see only one direction of the animation, i only see the fadeout

我做的尝试是:beforChange =淡出和的onChange或淡入后

What i try is: beforChange = fadeOut and onChange or after fadein

下面是我活动的onCreate方法我的code:

here is my code in the onCreate method of my activity:

    final Animation out = new AlphaAnimation(1.0f, 0.0f);
    out.setDuration(1000);

    final Animation in = new AlphaAnimation(0.0f, 1.0f);
    in.setDuration(1000);


    bidFirst.setAnimation(out);
    bidMiddle.setAnimation(out);
    bidLast.setAnimation(out);

    TextWatcher bidWatcher = new TextWatcher() {
      public void onTextChanged(CharSequence s, int start, int before, int count) {
        in.startNow();
        bidFirst.setAnimation(out);
        bidMiddle.setAnimation(out);
        bidLast.setAnimation(out);
      }

      public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        out.startNow();
        bidFirst.setAnimation(in);
        bidMiddle.setAnimation(in);
        bidLast.setAnimation(in);
      }

      public void afterTextChanged(Editable s) {
      }
    };
    bidFirst.addTextChangedListener(bidWatcher);
    bidMiddle.addTextChangedListener(bidWatcher);
    bidLast.addTextChangedListener(bidWatcher);

我觉得有什么不对我的code,但我相信它有工作。

i think there is something wrong in my code but for my believe it has to work.

我现在已经是:!?每一个的setText更改文本只淡出,但文本已更改后,从来没有淡入

What i have now is: on every setText the changed Text only FadeOut but after the text has changed and never FadeIn!?

推荐答案

TextSwitcher的正是你所期待的。只要使用他们的 setInAnimation() setOutAnimation 。比如果你改变了文本动画会自动运行的setText()

TextSwitcher is exactly what you are looking for. Just use their setInAnimation() and setOutAnimation. Than the animations will run automatically if you change the text by setText()

这篇关于如何动画淡出和淡入TextView的同时改变文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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