容易设置TextView 跑马观花效果
<TextView
android:id="@+id/top_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_alignWithParentIfMissing="true"
android:layout_centerInParent="true"
android:layout_toLeftOf="@id/top_btn_right"
android:layout_toRightOf="@id/top_btn_left"
android:enabled="true"
android:scrollHorizontally="true"
android:gravity="center"
android:focusable="true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:textColor="#ffffffff"
android:textSize="24.0sp" />
1.加蓝色部分注意啦都必须加上,不然没效果!原因是其他视图影响后 android:focusable="true"可能获取不到焦点。
2.所以加上android:focusableInTouchMode="true" 解决获取不到焦点,触摸模式获取后及滚动开始。
3.如果还是不能解决效果就只能在代码中获取焦点了,使用textview.requestFocus() 方法获取。