Android开发 TextView实现跑马灯效果

第一种,运用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"
	            />



 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值