返回
顶部

修改密码

TextView文字横向滚动(跑马灯效果)

+1

-1

收藏

+1

-1

点赞0

评论0

TextView实现文字滚动需要以下几个要点:1、文字长度长于可显示范围:android:singleLine="true";2、设置可滚到,或显示样式:android:ellipsize="marquee";3、TextView只有在获取焦点后才会滚动显示隐藏文字,所以可以重写TextView类。(但是一直给予焦点可能会导致其不能…
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” ——以跑马灯的方式显示(动画横向移动)

扫一扫在手机打开

评论
已有0条评论
0/150
提交
热门评论
相关推荐
今日要闻
换一批
热点排行