TextView 跑马灯效果

简介: TextView 跑马灯效果

1、重写TextView

class TextViewMarquee : AppCompatTextView {
    constructor(context: Context?) : super(context!!) {}
    constructor(context: Context?, attrs: AttributeSet?) : super(
        context!!, attrs
    ) {
    }
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context!!, attrs, defStyleAttr
    ) {
    }
    /**
     * 必须重写改方法设置为true
     * @return Boolean
     */
    override fun isFocused() = true
}

2、布局文件中配置

<com.demo.basis.weight.TextViewMarquee
                android:id="@+id/mMarquee"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:ellipsize="marquee"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="center"
                android:marqueeRepeatLimit="marquee_forever"
                android:singleLine="true"
                android:text="我就是一个跑马灯!!!我就是一个跑马灯!!!我就是一个跑马灯!!!我就是一个跑马灯!!!"
                android:textColor="@color/black"   
                android:textSize="@dimen/sp_18" />

注:这四个方法是在xml中必须配置的


* android:ellipsize="marquee"

* android:focusable="true"

* android:focusableInTouchMode="true"

* android:gravity="center"

* android:marqueeRepeatLimit="marquee_forever"

* android:singleLine="true"


达到的效果befccf2c9f3c49ef9172005ec9f975e9.gif

目录
相关文章
|
26天前
|
Java Android开发
TextView设置跑马灯效果
TextView设置跑马灯效果
19 0
|
XML 数据格式
简单的TextView滚动跑马灯效果
今天遇到一个需求,需要TextVeiw 滚动显示,于是简单记录一下。
97 0
简单的TextView滚动跑马灯效果
EditText与TextView的开发中的常用属性,打造完美布局
EditText与TextView的开发中的常用属性,打造完美布局
59 0
|
Android开发
Android TextView跑马灯效果
Android TextView跑马灯效果
189 0
|
Android开发 数据格式 XML
TextView实现跑马灯效果
Android textView 实现跑马灯效果
1774 0
|
测试技术 Android开发