TextView 跑马灯

来源:互联网 发布:胡克霍根身体数据 编辑:程序博客网 时间:2024/06/06 03:32

废话不多说:

第一步:

<TextView        android:id="@+id/tv_n1"        android:layout_width="150dp"        android:layout_height="20dp"        android:singleLine="true"        android:ellipsize="marquee"        android:marqueeRepeatLimit="2"        android:textSize="18sp"        android:text="你好我好大家好!你好我好大家好!你好我好大家好!你好我好大家好!"        />

第二步:

在第一步的标签中加入

android:focusableInTouchMode="true"android:focusable="true"

在java代码中调用

n1.setSelected(true);

要点

  1. 虽然android:singleLine被弃用了,代码提示建议使用android:maxLines,但是写android:maxLines =1 他妈不好用啊,你说有多坑。必须写android:singleLine=”true” !
  2. 在xml中加标签属性 android:textIsSelectable 不好用!