使用TextView提供的属性让view中的文本以跑马灯的效果显示;
布局文件如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv_marquee_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:textSize="20sp"
android:focusableInTouchMode="true"
android:background="#FFFFFF"
android:textColor="#000"
android:layout_margin="10dip"
android:padding="10dip"
/>
</RelativeLayout>
android:singleLine="true"
用于设置显示的文本只限与一行;
android:ellipsize="marquee"
设置文本显示的方式,其中属性有:start表示为省略号显示在开头、end表示为省略号显示在结尾、middle表示为省略号显示在中间、marquee表示为跑马灯的方式显示(动画横向移动);
android:marqueeRepeatLimit="marquee_forever"
在设置过ellipsize属性并指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次数;
android:focusable="true"
设置是否获取焦点,跑马灯需要依据该属性才能有效果
android:focusableInTouchMode="true"
设置在touche模式下是否能取得焦点
通过设置以上的属性之后TextView中显示的文本就以跑马灯的效果显示;