Setting a TextView stops scrolling the scroll of another TextView

This was asked elsewhere, but the solution did not work for me. So this again creates more context. The problem is that the action contains a scrollable text representation of the music title, which is interrupted by an updated view of the elapsed time counter text.

I have two kinds of TextView widgets in my activity layout (although they are included in other layout layouts).

<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 name of the music is dynamically set to (in the test case) a long line of text. If I never update the text during the current time with the next line, the name of the music will joyfully scroll forever no matter how I interact with the pause and play buttons.

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

But if I set the text for the current time, the name of the music will stop. Pressing my pause button somehow starts to scroll back, but pressing play will update the current time and restart.

As per the suggestion in this thread, I tried to associate the time text setting with re-enabling the scroll header as follows:

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

This does not affect the failure, except for resetting the scroller each time it is restarted.

Are there any details that I'm missing, or any other thoughts on what might go wrong? Many thanks!

+8
android scroll marquee
source share
3 answers

The sign is problematic. When a TextView (or a Window containing a TextView) loses focus, the selection is highlighted and reset (see Sources for TextView). I think you have 3 possible solutions:

  • You can set android:focusable="false" in all other views in your layout. Thus, your TextView should not lose focus. But this is probably not the solution you want.
  • You can subclass TextView and change onFocusChanged() and onWindowFocusChanged() to prevent the selection from stopping and reset.
  • Create your own tent implementation.
+7
source share

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

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

+5
source share

(Promotion of the comment above to the answer) It turns out that the TextView XML configurations above work fine, without any changes at runtime (until reset enabled = true or something else) IF I get rid of the RelativeLayout in my layout file and replace them with LinearLayout's. And not a single sentence 1 or 2 above (not sure about 3) works if I do not. This is similar to the subtle and dummy undocumented RelativeLayout failure.

+2
source share

All Articles