您的位置:首页 > 移动开发 > Android开发

Android开发 TextView实现跑马灯效果

2013-10-16 10:33 781 查看
第一种,运用TextView属性

<TextView
style="@style/show_cost_red_txt"
android:layout_toRightOf="@id/dao"
android:text="@string/show_nan"
android:id="@+id/end_point"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
/>

android:ellipsize="marquee"----跑马灯
android:singleLine="true"----单行显示
android:focusable="true"----该textView适中获取焦点,只有获取焦点才能实现跑马灯效果,如果是多个TextView列表需要把这个属性去掉才能实现点击那个view那个view跑
android:marqueeRepeatLimit="marquee_forever"----一直循环跑
android:focusableInTouchMode="true"----必须有

第二种,重写TextView类,可以实现多个TextView同时实现跑马灯效果

package com.online.bchd.jsk.view;
/**
* @author
* @time

* @info 重写textview实现字符过长的跑马灯效果*/
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

public class MForeverTextView extends TextView {

public MForeverTextView(Context context) {
super(context);
}
public MForeverTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MForeverTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean isFocused() {
return true;
}

}


布局文件中使用
<com.online.bchd.jsk.view.MForeverTextView
style="@style/show_cost_red_txt"
android:id="@+id/start_point"
android:text="@string/show_dong"
android:singleLine="true"
android:ellipsize="marquee"
/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: