[英]android - issue with auto scrolling in TextView
I have an Activity
which serves as a music player. 我有一个
Activity
作为音乐播放器。 When it starts, a MediaPlayer
object gets initialized and started. 启动时,
MediaPlayer
对象将被初始化并启动。 In the layout, I have TextViews
to display the artist and the title. 在布局中,我有
TextViews
来显示艺术家和标题。 Those values (retrieved from the server) can be long so I added 这些值(从服务器检索)可能很长,所以我补充说
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
to make the text scroll. 使文本滚动。 There is a strange issue: when I press the "pause" button, the
TextViews
are scrolling, but while the music is playing they don't scroll. 有一个奇怪的问题:当我按下“暂停”按钮时,
TextViews
正在滚动,但是在播放音乐时它们不会滚动。 Any ideas? 有任何想法吗?
PS I update the SeekBar
every 500ms using a Runnable
, could the issue be related to this? PS我使用
Runnable
每500ms更新一次SeekBar
,问题可能与此有关吗?
Here's my layout: 这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center_vertical"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/main_header"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
</LinearLayout>
<ImageView
android:id="@+id/imgCoverArt"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="@+id/main_header"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="20dp"
android:src="@drawable/cover_default" />
<SeekBar
android:id="@+id/seekBarMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imgCoverArt"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:paddingLeft="9dp"
android:paddingRight="9dp"
android:progressDrawable="@drawable/pb"
android:thumb="@drawable/pbhead" />
<TextView
android:id="@+id/tvArtist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seekBarMain"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvArtist"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/tvTimeElapsed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/seekBarMain"
android:layout_alignLeft="@+id/seekBarMain"
android:layout_marginBottom="-10dp"
android:text="02:54"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/tvTotalTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/seekBarMain"
android:layout_alignRight="@+id/seekBarMain"
android:layout_marginBottom="-10dp"
android:text="05:45"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/btnPrevious"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="6dp"
android:background="@drawable/prev_btn_state" />
<Button
android:id="@+id/btnPlay"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center_vertical"
android:background="@drawable/button_play" />
<Button
android:id="@+id/btnNext"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="3dp"
android:background="@drawable/next_btn_state" />
</LinearLayout>
</RelativeLayout>
<TextView
android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
add this your TextView, 添加这个你的TextView,
android:focusable="true"
android:focusableInTouchMode="true"
is needed to scroll automatically. 需要自动滚动。
More example are there in GitHub. GitHub中有更多示例。
https://github.com/FireZenk/FireZenk-s-TickerText https://github.com/FireZenk/FireZenk-s-TickerText
https://github.com/kaeppler/ignition/blob/master/ignition-core/ignition-core-lib/src/com/github/ignition/core/widgets/ScrollingTextView.java https://github.com/kaeppler/ignition/blob/master/ignition-core/ignition-core-lib/src/com/github/ignition/core/widgets/ScrollingTextView.java
Hope this will help you. 希望这会帮助你。
You can try this in you onCreate
method. 您可以在
onCreate
方法中尝试这个。
yourTexView.setMovementMethod(new ScrollingMovementMethod());
I have also faced exactly the same problem. 我也遇到了完全相同的问题。 Solved it this way.
解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.