[Android] TextView实现走马灯效果

    xiaoxiao2021-03-25  100

    转自:http://blog.csdn.net/crazyzhangcrazy/article/details/8594991

           在TextViw中,如果文本的长度超出了显示范围,可以使文本水平滚动显示,类似于走马灯的效果,只需在XML布局文件中,为TextView设置如下几个属性即可。

            Android:ellipsize="marquee"。

            android:marqueeRepeatLimit="XX"。其中XX表示循环次数,为大于0的整数或marquee_forever(无限循环)。

            android:focusable="true"。只有处于焦点状态的TextView才能显示走马灯效果。

     

           如下是完整的XML代码

    [html]  view plain  copy <?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/textview3"           android:layout_width="fill_parent"           android:layout_height="wrap_content"           android:text="start这里是一个使TextView实现走马灯效果的例子end"           android:singleLine="true"           android:ellipsize="marquee"           android:marqueeRepeatLimit="marquee_forever"           android:focusable="true"   android:focusableInTouchMode="true"         android:background="#FFF"           android:textColor="#000"           android:textSize="20dp"           android:layout_margin="10dp"           android:padding="10dp"/>   </LinearLayout>  

            实现效果如下图。

    转载请注明原文地址: https://ju.6miu.com/read-22342.html

    最新回复(0)