安卓 : How to display more than one Marquee simultaneously (focus for two marquees)

标签 android marquee

我想在我的应用程序中使用 2 个选取框。但只有一个一直在工作。如果我评论第一个,那么第二个就可以了。否则第一个。或者一次只有一个选取框获得焦点。如果我们按下向下箭头,那么第二个将获得焦点。这两个选框如何才能获得焦点?

如何同时显示 2 个跑马灯? 以下是我的代码:

 <RelativeLayout 
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:id="@+id/imgLogotb">

      <TextView 
                    android:id="@+id/txt1" 
                    android:layout_width="wrap_content" 
                    android:text="START | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | END" 
                    android:layout_height="20dip"
                    android:singleLine="false"
                    android:ellipsize="marquee"   
                    android:marqueeRepeatLimit="marquee_forever"
                    android:scrollHorizontally="true" 
                    android:focusable="true" 
                    android:focusableInTouchMode="true" 
                   android:freezesText="true">
     </TextView>

     <TextView 
                    android:id="@+id/txt2" 
                    android:layout_width="wrap_content" 
                    android:text="START | lunch 1.00 | Dinner 2.00 | Travel 3.00 | Doctor 4.00 | lunch 5.00 | Dinner 6.00 | Travel 7.00 | Doctor 8.00 | END" 
                    android:layout_height="20dip"
                    android:singleLine="false"
                    android:ellipsize="marquee"   
                    android:marqueeRepeatLimit="marquee_forever"
                    android:scrollHorizontally="true" 
                    android:focusable="true" 
                    android:focusableInTouchMode="true" 
                    android:freezesText="true">
      </TextView>
</RelativeLayout>

请帮我解决一下.... 谢谢...

最佳答案

现在,您可能会说,我为自己找到了补丁。选取框文本在聚焦时起作用。现在我们的目标是同时关注每个 textView。

为此,我们将创建自己的自定义 TextView 组件类,并将在方法 isFocusable() 中始终返回 true。开始了:

public class ScrollingTextView extends TextView {

    @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;
    }

 }

现在您所要做的就是将此 TextView 添加到您的 XML 布局中,如下所示。

<com.yourpackagename.ScrollingTextView
    android:text="LONG LONG LONG LONG text..................."
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:id="@+id/TextView03"
    android:padding="5dip" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />

大功告成,你可以在XML布局中任意多次添加这个TextView组件,所有的textView会同时跑马灯。

关于安卓 : How to display more than one Marquee simultaneously (focus for two marquees),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4489230/

相关文章:

android - 即使尝试了所有方法,我也无法在 Android 中获得字幕效果

c# - 如何让标签文字自动滚动?

html - CSS Marquee 添加更多文本行

css - 设置选取框文本动画的起始位置

java - 从 Intent 中检索信息,然后将其设置到 Fragment 内的 TextView - Android

android - 膨胀的框架布局上的按钮未触发点击事件

android - 通过 theme 设置 StatusBar 颜色。

java - 多 View 应用程序

javascript - 选取框,动态更改内容并重新开始滚动

android - Device Token 第一次返回null