首页 > 移动平台 > 详细

Android成长日记-仿跑马灯的TextView

时间:2015-02-26 20:07:33      阅读:320      评论:0      收藏:0      [点我收藏+]

在程序设计中有时候一行需要显示多个文字,这时候在Android中默认为分为两行显示,但是对于必须用一行显示的文字需要如何使用呢?

---------------------------------------------------------------------

以下列出解决方法:

1. 新建TextView控件

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:singleLine="true" //保留一行显示

android:ellipsize="marquee" //设置滚动方式

android:focusable="true"

android:focusableInTouchMode="true"

android:text="@string/demo"/>

2. 重写TextView控件的样式(新建MarqueeText.java)

public class MarqueeText extends TextView {

public MarqueeText(Context context) {

super(context);

}

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

super(context, attrs, defStyle);

}

public MarqueeText(Context context, AttributeSet attrs) {

super(context, attrs);

}

@Override

public boolean isFocused() {

return true; //默认为false,设置为true为了让每个TextView都获取焦点

}

}

3. 将<TextView />更改为<com.demo.marqueetextview.MarqueeText.java [s1]

------à>>>这样的话就实现了对TextView的重写

===================================================

以上方法即实现了仿跑马灯效果的TextView

2015-01-31


[s1]这个地方为重写的java文件所在的包(精确到java文件~)

Android成长日记-仿跑马灯的TextView

原文:http://www.cnblogs.com/boy1025/p/4301992.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!