展会信息港展会大全

TextView文字横向滚动(跑马灯效果)
来源:互联网   发布日期:2015-11-25 22:15:58   浏览:5462次  

导读:TextView实现文字滚动需要以下几个要点:1、文字长度长于可显示范围:android:singleLine="true";2、设置可滚到,或显示样式:android:ellipsize...

TextView实现文字滚动需要以下几个要点:

1、文字长度长于可显示范围:android:singleLine="true";

2、设置可滚到,或显示样式:android:ellipsize="marquee";

3、TextView只有在获取焦点后才会滚动显示隐藏文字,所以可以重写TextView类。(但是一直给予焦点可能会导致其不能被点击,如放在listView中的时候)

public class AlwaysMarqueeTextView extends TextView {

public AlwaysMarqueeTextView(Context context) {

super(context);

}

public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {

super(context, attrs);

}

public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

}

//始终返回true,即一直获得焦点

@Override

public boolean isFocused() {

return true;

}

布局文件中的TextView添加:

android:singleLine =“true”

android:focusable=“true”

android:marqueeRepeatLimit=“marquee_forever” //滚动次数,此时为无数次

android:ellipsize =“marquee”

ellipsize属性

设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港