网上百度了下制动滚动字幕,需要实现的步骤都挺多的,
下面我将使用简单的几步实现,当然,功能就没那么强大了只是简单的实现字幕滚动
效果如下:字幕会从右往左循环滚动
第一种:如果你不想自定义视图,只需要如下
<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让他继承TextView
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" />
简单几步便可实现字幕滚动效果