Android跑马灯实现

731 阅读1分钟

直接设置

android:singleLine="true"

单行显示的限制情况下,不能折行显示剩余文字,采用跑马灯的效果。

 

只有一个TextView时的解决方案

android:ellipsize="marquee"

使省略号编程省略文字。

android:focusable="true"

android:focusableInTouchMode="true"

效果最终实现。

 

两个以上的TextView解决方案

上述属性基础上

新建一个类

  将TextView使用自己建立的类

com.zrf.myapplication.MarqueeText

包名.新建类的名字

 

杂知识

android:layout_marginTop="10dp"

控件之间的距离属性

 

右击继承过来的TextView选择Generate中的Constructor 即可选中构造函数