4

アプリケーションに 2 つのマーキーが必要です。しかし、常に1つだけが機能しています。最初のものにコメントすると、2番目のものは機能します。そうでなければ最初のもの。または、一度に 1 つのマーキーのみがフォーカスされます。下矢印を押すと、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;
    }

 }

これで、次のようにこの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" />

これで、このTextViewコンポーネントをXMLレイアウトで何度でも追加でき、すべてのtextViewが同時にマーキーになります。

于 2011-08-02T05:37:47.193 に答える