Android实现文字显示跑马灯效果


(1)单个TextView实现跑马灯效果

  <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="@string/textContent" />
</pre><pre name="code" class="html">其中 <string name="textContent">不过,他想,我的钓线深度很精确,只不过是我走运而已。可是谁知道呢?也许就在今天呢。每一天都是个崭新的日子。走运固然不错,不过我宁可保持精确。那样,机会来临时,你已经做好了准备。但是人不是为打败而生的,一个人可以被毁灭,却不能被打败。----《老人与海》</string>


(2)多个Textview实现跑马灯效果

自定义一个类MarqueeText

package com.******.marqueetextview;

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

public class MarqueeText extends TextView {

	public MarqueeText(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public MarqueeText(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public MarqueeText(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	<strong>public boolean isFocused() {
		// TODO Auto-generated method stub
		return true;
	}</strong>

}


<com.******.marqueetextview.MarqueeText
        android:id="@+id/text5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="@string/textContent" />





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值