废话不多说:
第一步:
<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);
要点
- 虽然android:singleLine被弃用了,代码提示建议使用android:maxLines,但是写android:maxLines =1 他妈不好用啊,你说有多坑。必须写android:singleLine=”true” !
- 在xml中加标签属性 android:textIsSelectable 不好用!