您的位置:首页 > 移动开发 > Android开发

Android TextView跑马灯效果

2015-02-23 21:03 399 查看

TextView跑马灯简单效果

<!--简单示例-->
<TextView
android:text="@string/longWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"

android:ellipsize="marquee"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
/>


TextView跑马灯效果的几个常用属性,其中ellipsize、singleLine、focusable、focusableInTouchMode 这几个是必须的,其他可选

<!--激活焦点-->
android:focusable="true"
<!--单行显示-->
android:singleLine="true"
<!--这里设置为超出文本后滚动显示-->
android:ellipsize="marquee"
<!--这个是设置滚动几次,这里是无限循环-->
android:marqueeRepeatLimit="marquee_forever"
<!--TouchMode模式的焦点激活-->
android:focusableInTouchMode="true"
<!--横向超出后是否有横向滚动条-->
android:scrollHorizontally="true"


效果图:

<TextView
android:text="@string/longWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"

android:ellipsize="marquee"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
/>

<sh.geeko.marqueetext.marqueeText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:text="@string/longWord"
android:layout_below="@id/textView1"
android:layout_marginTop="20dp"

android:ellipsize="marquee"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
/>


View Code
这里我们来看下具体的实现效果:



源码下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: