Search code examples
javaandroidandroid-layouttextviewmarquee

Running TextView failure/Bug (Singleline marquee)


Im trying to let my textview run from left to right in an infinite way.But somehow it looks really weird I even cant explain it in words so I decided to record and upload it.

Here is the video : https://www.youtube.com/watch?v=gj3FF7fEutk&feature=youtu.be

So thats how I wrote my Textview :

<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:singleLine="true"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit ="marquee_forever"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:scrollHorizontally="true"

            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Title"
            android:layout_marginTop="20dp"
            android:textColor="@color/white"
            android:id="@+id/textView_title_full"
            android:layout_centerHorizontal="true" />

And this TextView is in a RelativeLayout declared like this :

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="170dp"
            android:id="@+id/BELOW_FULL"
            android:layout_gravity="bottom"
            android:background="@drawable/color_below_player_full"
            android:layout_below="@+id/viewpager_albumart_full"
            android:layout_alignParentBottom="true">

where the RelativeLayout is also in a Relativelayout like this :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:background="#0E0E0E">

I of course used the txt_song_title.setSelected(true); method.

How it looks like what I want to achieve :https://www.youtube.com/watch?v=o4uAA4pik68

Thank you all very much !

EDIT:

All parts where I do sth with my TextView :

public void init_textviews()
{
        ...
        txt_song_title = (TextView)findViewById(R.id.textView_title_full);
        txt_song_title.setSelected(true);
} 

//init_textviews() is called in my onCreate method

txt_song_title.setText("Some Long text"); // called in onCreate after init_textviews()

And lastly:

public static void update_GUI_full (Context context) //Called when it is a button is clicked
{
    ...
    txt_song_title.setText("longTexthere");
    ...
}

Solution

  • Working side by side with @Ahmet Kazaman we've found that there seemed to be a problem when combining a marquee TextView with another TextView periodically updated using a Handler.

    After some tests we've found that this strange behaviour only happens when the TextViews are iside a RelativeLayout and everything woeks as expected when the enclosing layout is a LinearLayout. Thus, the solution (more a workaround) is to change the enclosing layout to be a Linearlayout.