Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting of TextView stops marquee scrolling of other TextView

This was asked elsewhere, but the solution did not work for me. So posing it again with more context. The issue is that an activity contains a scrolling music title text view which is disrupted by an updating elapsed time counter text view.

I have these two TextView widgets in my activity layout (although they are encompassed by other layout containers).

<TextView android:id="@+id/v_current_time"
   android:minWidth="26dp"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center_vertical"
   android:gravity="right|center_vertical"
   android:singleLine="true"
   android:textSize="12sp"
   android:enabled="false"
  />

<TextView android:id="@+id/v_track_title"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textSize="18sp"
   android:textStyle="normal"
   android:singleLine="true"
   android:ellipsize="marquee"
   android:marqueeRepeatLimit="marquee_forever"
   android:scrollHorizontally="true"
   android:focusable="true"
   android:focusableInTouchMode="true"
   android:enabled="true"
/>

The music title is dynamically set to (in the test case) a long line of text. If I never update the text for the current time with the following line, the music title will happily scroll forever no matter how I interact with my pause and play buttons.

tvCurrentTime.setText(DataFormat.formatTime(progress));

But if I do set the text for the current time, the music title will stop. Pressing my pause button somehow kicks scrolling back into gear, but pressing play will cause the current time to update and stop it again.

Per the suggestion in this thread, I attempted to couple the setting of the time text with re-enabling of the scrolling title as follows:

tvCurrentTime.setText(DataFormat.formatTime(progress));
tvTitle.setEnabled(true);

This has no effect on the failure other than to reset the scroller each time it restarts.

Is there some detail that I am missing, or any other thoughts as to what could be going wrong? Thanks a lot!

like image 704
Groovee60 Avatar asked Sep 03 '11 17:09

Groovee60


2 Answers

There is another way to solve this without removing all RelativeLayout.

You can simply wrap the marquee TextView with a LinearLayout inside the RelativeLayout as a container.

like image 122
Patrick Chan Avatar answered Sep 20 '22 00:09

Patrick Chan


Marquee is problematic. When TextView (or the Window containing the TextView)loses focus the marquee is stopped and reset (see the sources for TextView). I guess you have 3 possible solutions here:

  1. You can set android:focusable="false" in all other Views in your layout. That way your TextView shouldn't lose focus. But that's probably not the solution you want.
  2. You can subclass TextView and change onFocusChanged() and onWindowFocusChanged() to prevent marquee from being stopped and reset.
  3. Create your own implementation of marquee.
like image 23
Tomik Avatar answered Sep 18 '22 00:09

Tomik