走马灯

250 阅读1分钟

##一、描述
走马灯的实现,两种方法

##二、方法

#####第一种: 自定义一个类继承TextView,重写它的isFocused()方法在布局的文件中使用自定义的TextView,可以使用与列表的跑马灯实现

//继承TextView并且实现抽象方法
public class FocusedTextView extends TextView {

    public FocusedTextView(Context context, AttributeSet attrs, int defStyle){
        super(context, attrs, defStyle);
    }

    public FocusedTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FocusedTextView(Context context) {
        super(context);
    }

    //重写isFocused方法,让其一直返回true
    public boolean isFocused() {
        return true;
    }
}

在清单文件中使用该类

<com.example.junwen.myapplication.View.MyTextView
        android:id="@+id/main_item_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:text="我是你的嘎嘎嘎、、、、、、、、哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈" />

#####第二种: TextView实现跑马灯的效果,不用自定义View,用于一个条码的跑马灯 ``` ```