Android跑马灯效果

jopen 10年前

当文字内容超过控件内容时,在控件内滚动的效果就是跑马灯效果。往下主要以TextView为例,EditText,Button类似;

<TextView        android:layout_height="wrap_content"       android:layout_width="fill_parent"       android:textSize="30px"       android:text="hello,my name is linyuhuan,i am come from canada,where are you come from?"       android:singleLine="true"       //是否当行显示文本       android:ellipsize="marquee"//文本超过控件长度,如何处理文本内容,此处为滚动动画显示       android:focusable="true"        //是否获得焦点       android:focusableInTouchMode="true"    //是否在触摸模式下获得焦点       android:marqueeRepeatLimit="marquee_forever"//重复滚动的次数       />

<TextView 

   android:layout_height="wrap_content"    android:layout_width="fill_parent"    android:textSize="30px"    android:text="11111111111111111111111133333333333344444444488888889999999992"    android:singleLine="true"    android:ellipsize="marquee"    android:focusable="true"    android:focusableInTouchMode="true"/>

运行的结果只有第一个有跑马灯效果。

注意:

(1)Android的缺省行为是在控件获得Focus时才会显示走马灯效果

(2)对于一个大View中有很多子View来说,同一时刻只能有一个子View获得focus!也就是说当前这一屏上,最多只能有一个view能有跑马灯效果,而不能多个View同事都有跑马灯效果。