(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>
自定义一个类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" />