Android让文本自动滚动实现
来源:互联网 发布:vb产品介绍格式 编辑:程序博客网 时间:2024/05/22 01:49
在实际开发中,TextView这个控件用到的情况是非常高的,因为也会诞生各种各样的需求,比如今天要探讨的文本自动滚动。正常情况下,让文本滚动则必须要让TextView获取焦点,但是,更多的情况是我们不仅需要文本滚动,还要进行别的操作,这时,再按正常的做法可能就实现不了了。不过我们只需要才去一点取巧的办法就能完美实现了,好了,废话不多说。
下面直接上代码,先是在xml里配置的代码:
<com.xxxx.xxxxx.xxxxx.view.AlwaysMarqueeTextView android:id="@+id/tvConsigneeAddress" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true" />
然后是Java实现代码:
import android.content.Context;import android.util.AttributeSet;import android.widget.TextView;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); } @Override public boolean isFocused() { return true; }}
好了,是不是很简单,这样之后,就可以实现让文本自动滚动的效果了。希望对你有帮助!
0 0
- Android让文本自动滚动实现
- 实现TextView自动左右滚动文本
- TextSwitcher实现文本自动垂直滚动
- TextSwitcher-------->实现文本自动垂直滚动
- TextSwitcher实现文本自动垂直滚动
- 关于android TextView在不需要较焦点的情况下,自动滚动文本实现小技巧
- android 实现ScrollView自动滚动
- Android:文本过长,实现添加滚动条
- 让ListView自动滚动
- 让ListView自动滚动
- 让ListView自动滚动
- 自定义UI-TextView实现文本自动滚动显示
- Android文字跑马灯控件(文本自动滚动控件)
- Android文字跑马灯控件(文本自动水平滚动)
- android实现歌词的自动滚动
- android TextView 垂直自动滚动字幕实现
- android TextView 垂直自动滚动字幕实现
- android TextView 垂直自动滚动字幕实现
- VR: AR和VR演进哲学
- 【第十二章】零配置 之 12.1 概述 ——跟我学spring3
- split和explode的区别
- <img src=1 onerror="alert('Welcome to My CSDN Blog');">
- FairSync与NonFairSync比较
- Android让文本自动滚动实现
- Android首选项
- 使用VS2013调试汇编代码
- 【第十二章】零配置 之 12.2 注解实现Bean依赖注入 ——跟我学spring3
- 对TreeMap中的值进行排序
- 八款开源Android游戏引擎
- 【第十二章】零配置 之 12.3 注解实现Bean定义 ——跟我学spring3
- IOS 如何正确使用正则表达式
- IPhone 6的自适应布局