TextView跑马灯效果实现
来源:互联网 发布:软件为什么需要预约 编辑:程序博客网 时间:2024/05/18 00:22
如果想让textView做出跑马灯的效果,必须使用TextView的一个属性就是
android:ellipsize="marquee"这个属性,但是这个属性的使用是需要这个控件是一直有焦点的,所以需要着自己进行自定义View的编写的,所以采用如下步骤:
1、自定义TextView
//获取焦点的textViewpublic class MyTtxtView extends TextView { //用代码new对象的时候会走此方法 public MyTtxtView(Context context) { super(context); } //有属性的时候会走到这个地方, public MyTtxtView(Context context, AttributeSet attrs) { super(context, attrs); } //有style的样式的话会走到这个方法 public MyTtxtView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } //表示有没有获取焦点 //跑马灯的话,,,首先需要调用这个方法判断是否有焦点 //只有设置成true的话,跑马灯才会有效果 //强制设置为有焦点 @Override public boolean isFocused() { return true; }}
2、替换原来布局文件中的TextView,变成自己的自定义的TextView
<com.lensman.a360.MyTtxtView android:id="@+id/advertisement" android:text="这是我第二次站在这里回味那种孤单了,也是最后一次。 上一次来的时候,是陈嫣然随我一道的。那是个刚下过雨的傍晚,一切都被雾气笼罩。本文原创于鬼大爷鬼故事网,转载请注明原作者及出处,否则视为侵权。原文链接:http://www.guidaye.com/dp/49028.html" android:lines="1" android:ellipsize="marquee" android:layout_below="@+id/main_title_tv" android:textColor="@color/black" android:layout_width="match_parent" android:layout_height="wrap_content" />
在这里面需要注意的是,必须将文本的行数设置成单独的一行
其实最简单的方法是如下的方法
android:focusable="true"android:focusableInTouchMode="true"
加这两个字段就可以了
阅读全文
0 0
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- textview实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- TextView 实现跑马灯效果
- TextView 实现跑马灯效果
- TextView实现跑马灯效果
- textView跑马灯效果实现
- TextView实现跑马灯效果
- textview实现跑马灯效果
- webservice Client 生成
- iOS中UIWebView与WKWebView、JavaScript与OC交互、Cookie管理看我就够(下)
- javascript学习笔记(一)
- [RK3288][Android6.0] MediaCodec的configure配置过程小结
- Paint 全面解析
- TextView跑马灯效果实现
- OpenCV实现的SSIM
- WebView笔记一
- c/c++中关键字static和const的用法
- java虚拟机参数
- JS面试之数组去重和快速排序
- 卷积的物理意义
- svn: E220003: Invalid authz configuration
- HashMap的存储原理