我尝试在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()