TextView 的设置停止其他 TextView 的选取框滚动 [英] Setting of TextView stops marquee scrolling of other TextView

查看:60
本文介绍了TextView 的设置停止其他 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.

我的活动布局中有这两个 TextView 小部件(尽管它们被其他布局容器包含).

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!

推荐答案

有另一种方法可以解决这个问题,而无需删除所有 RelativeLayout.

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

您可以简单地将选取框 TextView 用 LinearLayout 包裹在 RelativeLayout 内作为容器.

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

这篇关于TextView 的设置停止其他 TextView 的选取框滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆