频道栏目
首页 > 资讯 > Android > 正文

[Android] TextSwitcher -- 做什么的

15-04-12        来源:[db:作者]  
收藏   我要投稿

TextSwitcherJava 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控件
    
    
第2步:为TextSwitcher控件设置工厂(用于生产视图)
        mTs.setFactory(new TextSwitcher.ViewFactory() {
            @Override
            public 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)来切换文本时就会产生如下效果:
TextSwitcher效果

 

相关TAG标签
上一篇:iOS 中 run loop 浅析
下一篇:iosGCD线程安全之资源共享
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站