介绍
默认为无限次循环的横向跑马灯TextView
代码import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* ================================================
* Description:
*
* Created by Alex on 2020/11/30 0030
*
* 页面内容介绍:
*
* ================================================
*/
public class MarqueeText extends androidx.appcompat.widget.AppCompatTextView {
public MarqueeText Context context) {
super(context);
}
public MarqueeText Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeText Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//设置文字内容超过textView宽度时候以跑马灯的形式
setEllipsize(TextUtils.TruncateAt.MARQUEE);
//设置焦点
setFocusable(true);
//设置触摸模式下是否可以获得焦点
setFocusableInTouchMode(true);
//设置跑马灯循环次数 -1为always 无限循环 3就是3次 4就是4次 0没试过
setMarqueeRepeatLimit(-1);
}
/**
* 重写isFocused方法始终获得焦点来播放跑马灯
*
*
*/
public boolean isFocused() {
return true;
}
}
介绍
默认为无限次循环的横向跑马灯TextView
代码import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* ================================================
* Description:
*
* Created by Alex on 2020/11/30 0030
*
* 页面内容介绍:
*
* ================================================
*/
public class MarqueeText extends androidx.appcompat.widget.AppCompatTextView {
public MarqueeText Context context) {
super(context);
}
public MarqueeText Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeText Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//设置文字内容超过textView宽度时候以跑马灯的形式
setEllipsize(TextUtils.TruncateAt.MARQUEE);
//设置焦点
setFocusable(true);
//设置触摸模式下是否可以获得焦点
setFocusableInTouchMode(true);
//设置跑马灯循环次数 -1为always 无限循环 3就是3次 4就是4次 0没试过
setMarqueeRepeatLimit(-1);
}
/**
* 重写isFocused方法始终获得焦点来播放跑马灯
*
*
*/
public boolean isFocused() {
return true;
}
}
介绍
默认为无限次循环的横向跑马灯TextView
代码import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* ================================================
* Description:
*
* Created by Alex on 2020/11/30 0030
*
* 页面内容介绍:
*
* ================================================
*/
public class MarqueeText extends androidx.appcompat.widget.AppCompatTextView {
public MarqueeText Context context) {
super(context);
}
public MarqueeText Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeText Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//设置文字内容超过textView宽度时候以跑马灯的形式
setEllipsize(TextUtils.TruncateAt.MARQUEE);
//设置焦点
setFocusable(true);
//设置触摸模式下是否可以获得焦点
setFocusableInTouchMode(true);
//设置跑马灯循环次数 -1为always 无限循环 3就是3次 4就是4次 0没试过
setMarqueeRepeatLimit(-1);
}
/**
* 重写isFocused方法始终获得焦点来播放跑马灯
*
*
*/
public boolean isFocused() {
return true;
}
}