2016-04-20 7 views
1

TextView(TextView Aと呼ぶ)の単語がStringで、もう1つがTextView(TextView B)のタイマーで、このようなハンドラーで更新されているとします。。runOnUiThreadはマーキーのTextViewを防止しますか?

TextViewBのHandlerが毎秒更新されるたびに、TextView Aがmarquee animationを実行しないようにするのが問題です。

ここで私はTextView Bを更新するために使用しているコード...

public void updateTextViewB() 
{ 
    Thread thread = new Thread() { 

     @Override 
     public void run() { 
      getActivity().runOnUiThread(new Runnable() { 
       @Override 
       public void run() { 

        // Code that set's the constantly updating time 

        mHandler.postDelayed(this, 100); 
       } 
      }); 
     } 
    }; 

    thread.start(); 
} 

だオプションは、この問題を解決するために、ここでは何ですか?フォーカスをTextView Aに設定する必要がありますか?

+0

バックグラウンドスレッドまたはUIスレッドで実行されるハンドラはありますか? –

+0

uiスレッド、私は仮定しています。 –

+0

ネストされた 'run()'ではなくカスタム 'textview'を作成する方が良いです –

答えて

0

私は同じ問題を抱え、それを解決しました。 TextView AとBが同じレイアウトにある場合、それらは兄弟です。兄弟(A自身を含む)のフォーカスに更新があるたびにマーキーアニメーションが再開します。 Bが更新されるたびに、フォーカスが要求され、マーキーアニメーションが再開されます。溶液?あなたがする必要があるのは、それ自身のレイアウトにAを入れるだけなので、兄弟はなく、親は1つだけです。

<LinearLayout 
       android:id="@+id/mainLayout" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 
    <TextView 
       android:id="@+id/text_b" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="text being updated each second" 
       /> 

    <LinearLayout 
       android:id="@+id/marquee_text_container" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 


     <TextView 
       android:id="@+id/text_b" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:focusable="true" 
       android:focusableInTouchMode="true" 
       android:marqueeRepeatLimit="marquee_forever" 
       android:singleLine="true" 
       android:text="Long text with marquee animation that keeps running on the screen :P :)" 
       /> 
    </LinearLayout> 
</LinearLayout> 
関連する問題