網上百度了下制動滾動字幕,須要實現的步驟都挺多的,android
下面我將使用簡單的幾步實現,固然,功能就沒那麼強大了只是簡單的實現字幕滾動安全
效果以下:字幕會從右往左循環滾動ide
第一種:若是你不想自定義視圖,只須要以下佈局
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:focusableInTouchMode="true" android:singleLine="true" android:text="最新的仔仔手機安全衛士,快來下載啊,下載送好吃的。最新的仔仔手機安全衛士,快來下載啊,下載送好吃的。最新的仔仔手機安全衛士,快來下載啊,下載送好吃的。" android:textSize="18sp" />
即可實現字幕滾動,固然,視覺效果不大好,會展現出一個button的樣式
第二種:自定義一個view讓他繼承TextViewui
package com.zaizai.safty.ui; import android.content.Context; import android.util.AttributeSet; import android.view.ViewDebug; import android.widget.TextView; /** * Created by zaizai on 2015/10/13. */ public class FocusedTextView extends TextView { public FocusedTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public FocusedTextView(Context context, AttributeSet attrs) { super(context, attrs); } public FocusedTextView(Context context) { super(context); } /** * 當前並無焦點,欺騙系統 */ @Override @ViewDebug.ExportedProperty(category = "focus") public boolean isFocused() { return true; } }
佈局文件
<com.zaizai.safty.ui.FocusedTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" //必定要設計這個,才能滾動 android:focusableInTouchMode="true" android:singleLine="true" //使文字單行顯示 android:text="最新的仔仔手機安全衛士,快來下載啊,下載送好吃的。最新的仔仔手機安全衛士,快來下載啊,下載送好吃的。最新的仔仔手機安全衛士,快來下載啊,下載送好吃的。" android:textSize="18sp" />
簡單幾步即可實現字幕滾動效果