4

我想在我的应用程序中使用 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>

请通过提供解决方案帮助我....谢谢...

4

1 回答 1

4

现在我为自己找到了一个补丁,你可能会说。选取框文本在对焦时起作用。现在我们的目标是同时关注每个 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;
    }

 }

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

<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 将同时选取。

于 2011-08-02T05:37:47.193 回答