布局文件:
<com.baofeng.tv.local.widget.MarqueeScrollTextView
android:id="@+id/tv_menu_conten"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="@dimen/dp_14"
android:layout_marginRight="@dimen/dp_15"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="1"
android:singleLine="true"
android:textColor="#FFFFFF"
android:textSize="@dimen/sp_22" />
以下是代码设置这个Textview的属性 必须要有焦点和跑马灯横向滑动的属性 已可以选择在XMl文件里面配置根据个人所需 我这个是在adapter使用控制
holde.tvMenuConten.setFocusable(true);
holde.tvMenuConten.setEllipsize(TruncateAt.MARQUEE);
holde.tvMenuConten.setHorizontallyScrolling(true);
下面就来重写Textview吧 实现跑马灯
/**重写Textview 实现跑马灯
* @author jiangbing
* @time 2015-5-15 上午11:44:02
*/
public class MarqueeScrollTextView extends TextView {
private static final String TAG = "MarqueeScrollTextView";
public MarqueeScrollTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MarqueeScrollTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MarqueeScrollTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused() {
return true;
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
// TODO Auto-generated method stub
// fobid call parent constructor
// super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
}