`

【Android】如何让跑马灯跑起来-控件请求焦点

阅读更多
[size=large]网上一般都讲了很多如何实现跑马灯的效果,但是很多情况下,我们的跑马灯跑不起来,这是为什么呢,让我们先看看这个跑马灯的一般代码。

<TextView android:layout_width="100px"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white" 
        android:ellipsize="marquee" 
        android:focusable="true" 
        android:marqueeRepeatLimit="marquee_forever" 
        android:focusableInTouchMode="true" 
        android:scrollHorizontally="true"
        android:text="这才是真正的文字跑马灯效果"
        >
    </TextView>



然而,这个跑马灯跑起来的一个必要条件是:这个textview或者button获取到了焦点。

所以,跑不起来的原因自然就是textview或者button没有获取到焦点了。
解决方法:在activity中,让对象去请求焦点

tv_paomadeng.requestFocus();
tv_paomadeng.setText("Whatever you want to display");


这样就万事大吉了![/size]
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics