有没有办法让 ellipsize=“marquee"?总是滚动? [英] Is there a way to make ellipsize="marquee" always scroll?

查看:49
本文介绍了有没有办法让 ellipsize=“marquee"?总是滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 TextView 上使用选取框效果,但只有在 TextView 获得焦点时才会滚动文本.这是一个问题,因为在我的情况下,它不能.

I want to use the marquee effect on a TextView, but the text is only being scrolled when the TextView gets focus. That's a problem, because in my case, it can't.

我正在使用:

  android:ellipsize="marquee"
  android:marqueeRepeatLimit="marquee_forever"

有没有办法让 TextView 总是滚动它的文本?我已经在 Android Market 应用程序中看到了这一点,应用程序名称将在标题栏中滚动,即使它没有获得焦点,但我在 API 文档中找不到这一点.

Is there a way to have the TextView always scroll its text? I've seen this being done in the Android Market app, where the app name will scroll in the title bar, even if it doesn't receive focus, but I couldn't find this being mentioned in the API docs.

推荐答案

我一直面临这个问题,我想出的最短解决方案是创建一个从 TextView 派生的新类.该类应覆盖三个方法 onFocusChangedonWindowFocusChangedisFocused 以使 TextView 全部聚焦.

I have been facing the problem and the shortest solution I have come up with is to create a new class derived from TextView. The class should override three methods onFocusChanged, onWindowFocusChanged and isFocused to make the TextView all focused.

@Override
protected 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 true;
}

这篇关于有没有办法让 ellipsize=“marquee"?总是滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆