How to animate text change in TextView?

岁酱吖の 提交于 2019-12-09 14:38:35

问题


Trying to do the following:

animTimeChange = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); 
itemTime.startAnimation(animTimeChange);
itemTime.setText("new text");

but the animation happens thru blank screen (i.e. original text is cleared, then new text appears with animation). How to avoid that blank screen?

(my TextView is part of ListView row, I've tried to use TextSwitcher - it doesn't work properly; for ViewFlipper - I am not sure where add Views there, since this is part of the ListView)


回答1:


TextSwitcher is exactly what you should be using for this. Check out the API Demo for TextSwitcher.

The way you should implement this is in your ListAdapter, provide TextSwitcher views to the ListView instead of TextViews. Then you can just call TextSwitcher.setText() on the list item you want to change.

Note that you should imediately get rid of your reference to the list item to avoid REALLY messing up listview.



来源:https://stackoverflow.com/questions/6270938/how-to-animate-text-change-in-textview

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