使用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" />
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" />
相关文章推荐
- 使用TextView实现跑马灯的效果
- Android控件笔记——使用TextView实现跑马灯效果
- Android使用TextView实现跑马灯效果
- 使用TextView实现跑马灯的效果
- 使用TextView实现跑马灯效果
- Android 高级UI设计笔记05:使用TextView实现跑马灯的效果
- 使用TextView可以实现跑马灯效果
- 使用TextView实现跑马灯效果
- Android中使用TextView实现文字跑马灯效果
- 使用TextView实现跑马灯效果
- 使用TextView实现跑马灯效果
- Android入门(3)——使用TextView实现跑马灯效果
- Android开发 第三课 使用TextView实现跑马灯效果
- 论TextView的超链接使用、显示表情、Html语法支持、跑马灯效果的实现
- 安卓控件使用系列4:TextView实现跑马灯效果
- 使用TextView实现跑马灯效果
- 使用TextView实现跑马灯效果
- android使用TextView实现文字的跑马灯效果
- Android使用TextView实现跑马灯效果
- TextView实现跑马灯效果