2017-07-08 6 views
2

Je fais un lecteur de musique et ai mis en place un chapiteau dans la chanson et le nom de l'artiste. Mais dès que la barre de recherche est mise à jour, la vue du texte revient à la position d'origine. Donc, de cette façon, une sorte de va-et-vient du texte est vu. Merci de m'aider.Marquee ne fonctionne pas avec la mise à jour de la barre de recherche. (Android)

Voici le code XML

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/mainFullPlayerContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 

    tools:context="com.musicplayer.integrated.sanket.music.MainFullPlayer" 
    android:background="@color/defaultBackground" 

> 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/relativeLayout" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true"> 

    <ImageView 
     android:id="@+id/imageView_full_player_more" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_marginTop="20dp" 
     android:layout_marginRight="15dp" 
     app:srcCompat="@drawable/icon_more" /> 
</RelativeLayout> 

<ImageView 
    android:id="@+id/imageView_full_player_album_art" 
    android:layout_width="300dp" 
    android:layout_height="300dp" 
    app:srcCompat="@drawable/default_album_art" 
    android:layout_marginTop="29dp" 
    android:layout_below="@+id/relativeLayout" 
    android:layout_centerHorizontal="true" /> 



<SeekBar 
    android:id="@+id/seekBar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 

    android:progressTint="@color/defaultTextColor" 
    android:thumbTint="@color/defaultTextColor" 
    android:layout_above="@+id/imageView_full_player_play" 

    android:layout_marginBottom="37dp" /> 

<ImageView 
    android:id="@+id/imageView_full_player_play" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="31dp" 
    app:srcCompat="@drawable/icon_play_small" /> 

<ImageView 
    android:id="@+id/imageView_full_player_next" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView_full_player_play" 
    android:layout_marginStart="39dp" 
    android:layout_toEndOf="@+id/imageView_full_player_play" 
    app:srcCompat="@drawable/icon_fast_next_small" /> 

<ImageView 
    android:id="@+id/imageView_full_player_prev" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView_full_player_play" 
    android:layout_marginEnd="38dp" 
    android:layout_toStartOf="@+id/imageView_full_player_play" 
    app:srcCompat="@drawable/icon_rewind_prev_small" /> 

<TextView 
    android:id="@+id/textView_full_player_song" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignEnd="@+id/imageView_full_player_album_art" 
    android:layout_alignStart="@+id/imageView_full_player_album_art" 
    android:layout_below="@+id/imageView_full_player_album_art" 
    android:layout_marginTop="12dp" 
    android:ellipsize="marquee" 
    android:focusable="true" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:scrollHorizontally="true" 
    android:singleLine="true" 
    android:text="Song Name" 
    android:textAlignment="center" 
    android:textColor="@color/defaultTextColor" 
    android:textSize="18sp" /> 

<TextView 
    android:id="@+id/textView_current_time" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="0:00" 
    android:textColor="@color/defaultTextColor" 
    android:textSize="12sp" 

    android:layout_marginBottom="18dp" 
    android:layout_above="@+id/imageView_full_player_prev" 
    android:layout_alignStart="@+id/textView_full_player_artist" /> 

<TextView 
    android:id="@+id/textView_total_length" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="5:00" 
    android:textSize="12sp" 
    android:textColor="@color/defaultTextColor" 
    android:layout_alignBaseline="@+id/textView_current_time" 
    android:layout_alignBottom="@+id/textView_current_time" 
    android:layout_alignEnd="@+id/textView_full_player_artist" /> 

<TextView 
    android:id="@+id/textView_full_player_artist" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignEnd="@+id/textView_full_player_song" 
    android:layout_alignStart="@+id/textView_full_player_song" 
    android:layout_below="@+id/textView_full_player_song" 
    android:layout_marginTop="12dp" 
    android:text="Artist" 
    android:textAlignment="center" 
    android:textColor="@color/defaultTextColor" 
    android:textSize="15sp" 
    android:ellipsize="marquee" 
    android:singleLine="true" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:focusable="true" 
    android:scrollHorizontally="true" 
    /> 

    </RelativeLayout> 

Here is the design

Voici le code Java

public class MainFullPlayer extends AppCompatActivity { 

private static RelativeLayout fullPlayer; 
private static ImageView fullPlayer_play , fullPlayer_next , 
fullPlayer_prev,fullPlayer_album; 
private static TextView fullPlayer_song , fullPlayer_artist , 
fullPlayer_currentTime , fullPlayer_maxTime; 
private static SeekBar seekBar; 
private Songs song; 
private static Handler progressHandler; 
private static Runnable progressRunnable; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main_full_player); 
    fullPlayer = (RelativeLayout)findViewById(R.id.mainFullPlayerContainer); 
    fullPlayer_play = (ImageView)findViewById(R.id.imageView_full_player_play); 
    fullPlayer_next = (ImageView)findViewById(R.id.imageView_full_player_next); 
    fullPlayer_prev = (ImageView)findViewById(R.id.imageView_full_player_prev); 
    fullPlayer_album = (ImageView)findViewById(R.id.imageView_full_player_album_art); 
    fullPlayer_song = (TextView)findViewById(R.id.textView_full_player_song); 
    fullPlayer_artist = (TextView)findViewById(R.id.textView_full_player_artist); 
    fullPlayer_currentTime = (TextView)findViewById(R.id.textView_current_time); 
    fullPlayer_maxTime = (TextView)findViewById(R.id.textView_total_length); 

    fullPlayer_maxTime.setText(MusicPlayback.getTime(MusicPlayback.mediaPlayer.getDuration())); 

    seekBar = (SeekBar)findViewById(R.id.seekBar); 

    song = MusicPlayback.allTracks.get(MusicPlayback.songPosition); 
    fullPlayer_song.setSelected(true); 
    fullPlayer_artist.setSelected(true); 
    fullPlayer_song.setText(song.getSongName()); 
    fullPlayer_artist.setText(song.getArtist()); 


    if(MusicPlayback.getPlayingStatus()){ 
     fullPlayer_play.setImageResource(R.drawable.icon_pause_small); 
    } 
    else 
    { 
     fullPlayer_play.setImageResource(R.drawable.icon_play_small); 
    } 
    if(song.getAlbumArt()!= null){ 

     fullPlayer_album.setImageURI(Uri.parse(song.getAlbumArt())); 
     fullPlayer.setBackground(FragmentAllTracks.d); 
    } 
    else{ 
     fullPlayer_album.setImageResource(R.drawable.default_album_art); 
     fullPlayer.setBackgroundColor(Color.argb(255, 48, 48, 48)); 

    } 
seekBar.setMax(MusicPlayback.mediaPlayer.getDuration()); 


    progressHandler = new Handler(); 

    progressRunnable = new Runnable() { 
     @Override 
     public void run() { 
      seekBar.setProgress(MusicPlayback.mediaPlayer.getCurrentPosition()); 
      fullPlayer_currentTime.setText(MusicPlayback.getTime(MusicPlayback.mediaPlayer.getCurrentPosition())); 


      progressHandler.postDelayed(progressRunnable,100); 
     } 
    }; 
    progressHandler.postDelayed(progressRunnable,100); 
} 


@Override 
public void onBackPressed() { 
    super.onBackPressed(); 
    this.overridePendingTransition(R.anim.left_exit_translate,R.anim.right_exit_translate); 

} 




} 

Voici le résultat

Unable to get Marquee

+0

add 'seekBar.setOnSeekBarChangeListener()' auditeur, Cochez cette https://stackoverflow.com/questions/9481977/android-seekbar-to-control-mediaplaye r-progress – Shailesh

+0

Veuillez me suggérer comment obtenir un effet de marque. Lisez la description attentivement. –

Répondre

0

Je pense que c'est en raison de la concentration. S'il vous plaît définir votre textview comme celui-ci

<TextView 
    android:id="@+id/textView_full_player_song" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignEnd="@+id/imageView_full_player_album_art" 
    android:layout_alignStart="@+id/imageView_full_player_album_art" 
    android:layout_below="@+id/imageView_full_player_album_art" 
    android:layout_marginTop="12dp" 
    android:singleLine="true" 
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit ="marquee_forever" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:scrollHorizontally="true" 
    android:text="Song Name" 
    android:textAlignment="center" 
    android:textColor="@color/defaultTextColor" 
    android:textSize="18sp" /> 

ajouter ce votre TextView,

android:focusable="true" 
android:focusableInTouchMode="true" 
+0

Monsieur veuillez lire la description et me suggérer des moyens de se débarrasser de mon problème. J'utilise la vue texte pour afficher la chanson et le nom de l'artiste dans le grand lecteur. Pour mettre à jour la barre de recherche, j'utilise le thread du gestionnaire. Mais après l'implémentation du thread, je suis incapable d'obtenir un effet de marque sur les TextViews. –

+0

S'il vous plaît vérifier mon code de réponse mis à jour – Shailesh

+0

Malheureusement, cela ne m'a pas aidé. :(Je suis toujours incapable d'obtenir un effet de marque sur l'implémentation du thread pour la barre de recherche. –

0

Essayez d'utiliser cette MarqueeTextView classe, il règle automatiquement la taille fixe pour TextView il ne sera pas re-mesure (la raison Cause animation de défilement de redémarrage):

public class MarqueeTextView extends AppCompatTextView implements View.OnLayoutChangeListener { 
    public MarqueeTextView(Context context) { 
     this(context, null); 
    } 

    public MarqueeTextView(Context context, AttributeSet attrs) { 
     this(context, attrs, 0); 
    } 

    public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     setSingleLine(); 
     setEllipsize(TextUtils.TruncateAt.MARQUEE); 
     setMarqueeRepeatLimit(-1); 
     setSelected(true); 

     addOnLayoutChangeListener(this); 
    } 

    @Override 
    public boolean isFocused() { 
     return true; 
    } 

    @Override 
    public void onWindowFocusChanged(boolean hasWindowFocus) { 
     if (hasWindowFocus) super.onWindowFocusChanged(hasWindowFocus); 
    } 

    @Override 
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { 
     if (focused) super.onFocusChanged(focused, direction, previouslyFocusedRect); 
    } 

    @Override 
    public void onLayoutChange(View v, int left, int top, int right, int bottom, 
           int oldLeft, int oldTop, int oldRight, int oldBottom) { 
     ViewGroup.LayoutParams layoutParams = getLayoutParams(); 
     layoutParams.height = bottom - top; 
     layoutParams.width = right - left; 
     removeOnLayoutChangeListener(this); 
     setLayoutParams(layoutParams); 
    } 
}