Widget 跑马灯
在Activity中让TextView具有跑马灯效果很简单。只需要加android:ellipsize="marquee",并且在java代码中requestFocus就好了。但是,要是在Widget中的TextView怎么办呢?(答案是:在Layout中加<requestFocus />)
Widget 中TextView的跑马灯效果
应为Widget程序中没有提供类似requestFocus这样的函数,因此只能在layout中加<requestFocus />,让Framework主动设置TextView为Focus.
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="monospace" >
<requestFocus />
</TextView>
另外,看了一篇文章可以让TextView在没有焦点的情况下也具有跑马灯效果。
android不获取焦点也可以实现跑马灯效果
参考自:http://liuyun025.iteye.com/blog/1395351,自定义TextView:
public class MarqueeTextView extends TextView{
private boolean mMarquee = false;
public MarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setMarquee(boolean marquee) {
mMarquee = marquee;
}
@Override
public void onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect) {
if (focused){
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
}
@Override
public void onWindowFocusChanged(boolean focused) {
if (focused){
super.onWindowFocusChanged(focused);
}
}
@Override
public boolean isFocused() {
return mMarquee;
}
}
posted on 2012-04-05 13:25 program_lover 阅读(404) 评论(0) 编辑 收藏 举报