android 文字超出控件宽度时,自动滚动显示,类似跑马灯效果
来源:互联网 发布:matlab画数据分布图 编辑:程序博客网 时间:2024/06/05 00:40
1.自定义控件
自定义RollTextView 继承TextView,重写 isFocused(),返回为ture 即可;
public class RollTextView extends TextView { public RollTextView (Context context) { super(context); } public RollTextView (Context context, AttributeSet attrs) { super(context, attrs); } public RollTextView (Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isFocused() { return true; }}
2.布局文件:
<com.ss.demo.RollTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:text="这是个TextView自动滚动效果示意案列,实现单行滚动效果" android:marqueeRepeatLimit="marquee_forever" android:ellipsize="marquee" android:scrollHorizontally="true" android:background="@drawable/bg_fff_25" android:textSize="20sp" android:textColor="#222" android:padding="5dp"/>
eandroid:ellipsize=”marquee”设置可以以横向滚动方式显示,但前提是需获得当前焦点,所以才有的上一步,重写 isFocused(),返回为ture则获取焦点;
android:marqueeRepeatLimit=”marquee_forever”设置跑马灯显示次数,marquee_forever表示不间断无限次,也可以通过代码textview.setMarqueeRepeatLimit(1)设置次数(设置-1 则是无限滚动);
android:scrollHorizontally=”true”设置水平显示;
3.效果图:
当显示的文字超出控件的宽度时,则自动滚动显示,不超过,则不滚动;
阅读全文
0 0
- android 文字超出控件宽度时,自动滚动显示,类似跑马灯效果
- Android文字跑马灯控件(文本自动滚动控件)
- Android文字跑马灯控件(文本自动水平滚动)
- 【Android】跑马灯效果(文字滚动)
- --------------------【Android】跑马灯效果(文字滚动)
- TextView跑马灯效果,也就是,自动滚动文字的效果。
- Android实现文字显示跑马灯效果
- Android文字跑马灯控件(文本自动滚动控件,左右移动 带源码)
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法[特别好使]
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法
- Android 文字自动滚动(跑马灯)效果的两种实现方法[特别好使]
- 跑马灯效果 文字上下滚动效果
- Qt5实现百度离线地图APIV2_0用QWebChannel实现Qt与js交互
- Metasploit阅读笔记1
- 7.1
- 博客第一次
- Handler或Runnable作为非静态内部类,引发的内存泄露问题
- android 文字超出控件宽度时,自动滚动显示,类似跑马灯效果
- TensorFlow模型保存的一个坑
- 安卓移动文件(图片)到指定目录,并在相册中显示
- Alias sampling 算法用Python实现
- 数据结构实验(二):间接寻址
- FFmpeg-3.3.1移植到Android平台
- document操作自定义属性
- Source Insight--艰难的编辑工具学习小记
- Java中的equals方法以及==