在ListView或GridView 中使用到跑马灯滚动效果实现的问题。
2015-06-17 14:42
531 查看
一般情况下TextView实现跑马灯效果只要设置一些几个属性即可实现了。
android:singleLine="true“//只显示单行
android:ellipsize="marquee" //实现滚动效果
android:focusable="true" //获取焦点,获取不到焦点是无法实现跑马灯滚动的
android:marqueeRepeatLimit="marquee_forever" // 无限循环滚动
android:marqueeRepeatLimit=”100“ 代表滚动100次
而且文字的长度大于控件的长度时才会出现跑马灯效果。
在Listview 或GridView 中由于其他控件的点击事件占取了焦点,使TextView无法获取到焦点,导致不能实现跑马灯的效果。
解决办法如下:
public class MyTextView 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);
}
@Override
public boolean isFocused() {
return true;
}
}
android:singleLine="true“//只显示单行
android:ellipsize="marquee" //实现滚动效果
android:focusable="true" //获取焦点,获取不到焦点是无法实现跑马灯滚动的
android:marqueeRepeatLimit="marquee_forever" // 无限循环滚动
android:marqueeRepeatLimit=”100“ 代表滚动100次
而且文字的长度大于控件的长度时才会出现跑马灯效果。
在Listview 或GridView 中由于其他控件的点击事件占取了焦点,使TextView无法获取到焦点,导致不能实现跑马灯的效果。
解决办法如下:
public class MyTextView 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);
}
@Override
public boolean isFocused() {
return true;
}
}
相关文章推荐
- Mac安装Brew
- 论坛推荐:数字电路如何抗干扰
- Android Gradle
- C++ 12.1 类的定义、声明、成员函数、数据成员
- Mac 更新svn
- Office2013激活
- 如何在面试中发现优秀程序员
- 浅谈使用NIO,AIO的感受
- ffmpeg 资源[转]
- 如何使用Python 打开exel等各种文件或者应用,就用:os.startfile
- Java Clob类型转String类型
- iOS、andoird解析报错JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain
- 通用顶部自定义控件 可在XML自定义属性
- linux 命令之tcpdump
- Audio Streaming mit UDP in C
- javascript 循环遍历绑定事件问题
- Merge k Sorted Lists 合并多个链表 归并 vector/copy
- 微软100题(94)找出数组中长度最长的等差数列
- 如何做一个好的产品数据
- In person Which i desire class just one excellent seeing that is it doesn't solely imitation wristwatches value taking