先發布一下佈局效果
<TextView
android:id="@+id/tv_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textSize="28sp"
android:text="路漫漫其修遠兮,吾將上下而求索3w3erweqrwqreqwreqwerwqrwrq"
android:textColor="#00ff00"
android:scrollHorizontally="true"/>
Activity的主要實現
//設置爲跑馬燈顯示
android:ellipsize="marquee"
//獲取焦點
android:focusable="true"
//可以通過toucth來獲得focus
android:focusableInTouchMode="true"
//設置重複的次數
android:marqueeRepeatLimit="marquee_forever"
//單行顯示文字
android:singleLine="true"