android代码库之textview跑马灯效果

来源:互联网 发布:淘宝地址武汉没有汉口 编辑:程序博客网 时间:2024/04/24 03:38
<span style="font-size:10px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/test" 
android:layout_width="100px"    这里一定要写在固定值
android:layout_height="wrap_content" 
android:textColor="@android:color/white"
android:ellipsize="marquee"      这里设置跑灯效果。
android:focusable="true"         这里设置是否可获得焦点
android:marqueeRepeatLimit="marquee_forever"    这里设置滚动的次数,在这里表示无限次



-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


<textview
android:layout_width = “100px”
android:layout_height = “wrap_content”
android:textColor = “@android:color/white”
android:ellipsize = “marquee”
android:focusable = “true”
android:marqueeRepeatLimit = “marquee_forever”
android:focusableInTouchMode = “true”
android:scrollHorizontally = “true”
android:text = “这才是真正的文字跑马灯效果”> 


在xml中

android:ellipsize = "end"    省略号在结尾

android:ellipsize = "start"   省略号在开头

android:ellipsize = "middle"     省略号在中间

android:ellipsize = "marquee"  跑马灯

最好加一个约束android:singleline = "true"


当然也可以用代码语句

tv.setEllipsize(TextUtils.TruncateAt.valueOf("END"));

tv.setEllipsize(TextUtils.TruncateAt.valueOf("START"));

tv.setEllipsize(TextUtils.TruncateAt.valueOf("MIDDLE"));

tv.setEllipsize(TextUtils.TruncateAt.valueOf("MARQUEE"));

最好再加一个约束tv.setSingleLine(true);

不仅对于textview有此属性,对于editext也有,不过它不支持marquee


原创粉丝点击