Android自定义TextView实现跑马灯效果
来源:互联网 发布:正装ps软件 编辑:程序博客网 时间:2024/04/29 05:21
TextView跑马灯效果
请遵守行规!
自己项目中用到,查资料的时候发现了很多方法,这里写下自己的用法,为了以后查看,也希望可以帮到用到的童鞋
- 第一种方法:在xml文件中直接写
如果在代码中直接使用textView自带的属性,需要在代码中对这个textView设置:setSelector(true);Android4.0之后必须加上 androidsingleLine=true
TextView androidlayout_width=400dip androidlayout_height=wrap_content androidlayout_marginLeft=80dip androidlayout_marginBottom=25dip androidtextSize=25sp androidid=@+idtv_marquee androidtextColor=@androidcolorblack androidellipsize=marquee androidfocusable=true androidmaxLines=1 androidsingleLine=true androidmarqueeRepeatLimit=marquee_forever androidfocusableInTouchMode=true androidscrollHorizontally=true androidtext=这才是真正的文字跑马灯效果,驾~驾~…… androidbackground=#2FFFFFFF
- 第二种方法:自定义TextView类
写一个类继承自TextView,然后把在xml文件中需要设置的属性在代码中设置,因为跑马效果和焦点有冲突,所以重写了onFocusChanged方法,为的只是不让其执行父类的方法
public class MarqueeText extends TextView { public MarqueeText(Context con) { super(con); } public MarqueeText(Context context, AttributeSet attrs) { super(context, attrs); } public MarqueeText(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isFocused() { return true; } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { }}
下面是xml文件,在xml文件中直接引用即可
com.thunder.ktv.helper.MarqueeTexView androidid=@+idtv_singerName androidlayout_width=wrap_content androidlayout_height=wrap_content androidlayout_marginLeft=10dp androidlayout_marginTop=10dp androidbackground=@null androidtext=歌手 androidtextColor=#d2d2d2 androidtextSize=16dp
0 0
- Android自定义TextView实现跑马灯效果
- Android 自定义textview实现跑马灯效果
- android自定义的TextView,实现跑马灯效果
- Android的自定义TextView实现跑马灯效果
- 自定义TextView实现跑马灯效果
- 自定义TextView实现跑马灯效果
- 自定义TextView实现跑马灯效果
- 自定义TextView实现跑马灯效果
- android 自定义textview跑马灯效果
- Android TextView跑马灯效果实现
- android textview跑马灯效果实现
- Android TextView实现跑马灯效果
- android TextView实现跑马灯效果
- android TextView实现跑马灯效果
- Android开发 TextView实现跑马灯效果
- android用TextView实现跑马灯效果
- Android TextView实现跑马灯效果
- Android TextView 跑马灯效果的实现
- [教程资源] HTC Vive UI Guideline
- bzoj2453/2120(分块)
- 数据结构与算法——单链表(一)
- 前言-嵌入式系统移植
- 第一个struts2工程:登录系统
- Android自定义TextView实现跑马灯效果
- C#数据类型详解
- HDU3631-Shortest Path
- 正则表达式常用方法
- 我的计划
- 高速数据总线kafka介绍
- POJ1200 Hash
- [JSOI2007]建筑抢修
- [JSOI2007]建筑抢修