2013-03-11 9 views
7

Ich habe eine Activity, die als Musik-Player dient. Beim Start wird ein MediaPlayer Objekt initialisiert und gestartet. Im Layout habe ich TextViews, um den Künstler und den Titel anzuzeigen. Diese Werte (vom Server abgerufen) können lang sein, so fügte ich hinzuandroid - Problem mit automatischem Scrollen in TextView

android:ellipsize="marquee" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:scrollHorizontally="true" 

um den Text zu blättern zu machen. Es gibt ein seltsames Problem: Wenn ich die "Pause" -Taste drücke, scrollen die TextViews, aber während die Musik abgespielt wird, scrollt sie nicht. Irgendwelche Ideen?

P.S. Ich aktualisiere die SeekBar alle 500ms mit einer Runnable, könnte das Problem damit zusammenhängen?

Hier ist mein 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> 
+0

Hallo Droidman, ich habe das gleiche Problem. Haben Sie eine Lösung dafür gefunden? –

Antwort

2
<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"/> 

dies Ihr Textview hinzufügen,

  android:focusable="true" 
      android:focusableInTouchMode="true" 

benötigt wird, automatisch zu scrollen.

Weitere Beispiele gibt es in GitHub.

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

Hope this Ihnen helfen.

+0

versuchte das, nichts änderte sich. Tatsächlich beginnt der Text automatisch zu scrollen, aber nur, wenn die Wiedergabe pausiert ist und die seekBar nicht aktualisiert wird. Und soweit ich weiß, kann nur eine Ansicht zu einem bestimmten Zeitpunkt fokussiert werden, aber in einigen Fällen muss ich TextViews automatisch scrollen lassen. Irgendwelche anderen Ideen? – Droidman

+0

haben Sie versucht https://github.com/FireZenk/FireZenk-s-TickerText? –

+0

warf einen Blick auf die Quelle, ich habe einige Zweifel, da das Ding ein Runnable verwendet und ich bereits eins und ein paar andere Dinge verwende .. (nur Speicherverwaltung Überlegungen, mein Player wird als "leichtgewichtig und effizient"). Wird dies als eine Option verlassen, danke – Droidman

0

Sie können dies in Ihnen onCreate Methode versuchen.

yourTexView.setMovementMethod(new ScrollingMovementMethod()); 

Ich habe auch genau das gleiche Problem konfrontiert. Auf diese Weise gelöst.