您的位置:首页 > 其它

使用TextView实现跑马灯效果

2017-05-19 15:51 369 查看
1、新建MarqueeTextView 继承自 TextView

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

public class MarqueeTextView extends TextView {

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

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

public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
public boolean isFocused() {
return true;
}
}

2、主布局文件xml代码

<com.leadingsoft.mbh.marqueetextview.MarqueeTextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:marqueeRepeatLimit="1"
android:scrollHorizontally="true"
android:text="@string/tv1" />

<com.leadingsoft.mbh.marqueetextview.MarqueeTextView
android:id="@+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:text="@string/tv2" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: