勿在浮沙筑高台

TextSwitcher的Java Doc是这样描述自己的:

Specialized ViewSwitcher that contains only children of type TextView. A TextSwitcher is useful to animate a label on screen. Whenever setText(CharSequence) is called, TextSwitcher animates the current text out and animates the new text in.

由此可知,TextSwitcher: – 有个TextView子视图 – 在文本更新时,能够让旧文本淡出,新文本淡入,从而呈现平滑切换的动画效果

如何使用TextSwitcher第1步:在layout中添加TextSwitcher控件 <TextSwitcher==”1″ ></TextSwitcher>第2步:为TextSwitcher控件设置工厂(用于生产视图)mTs.setFactory(new TextSwitcher.ViewFactory() {@Overridepublic View makeView() {final TextView tv = (TextView) LayoutInflater.from(getApplicationContext()).inflate(R.layout.text, null);return tv;}});第3步:设置淡入淡出动画mTs.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in));mTs.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out));

之后,执行mTs.setText(txt)来切换文本时就会产生如下效果:

注:完整代码在 GitHub

,生活中最基本的技巧是交流,最可依赖的品质是耐心,

勿在浮沙筑高台

相关文章:

你感兴趣的文章:

标签云: