Search code examples
androidxmlmarquee

Android : Unable to set marquee


I am not able to implement a Marquee Text View in android.

Yes, this question is similar to many other questions related to Marquee. I have read most of them. I tried implementing Marquee the way many of the answers are. But still my code doesn't work.

Please help me resolve the issue. I have tried everything. Nothing worked.

Thanks.

XML code :

<LinearLayout 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:gravity="center"
    android:orientation="vertical"
    android:background="@color/mainBg"
    tools:context=".MainActivity" >

<TextView android:layout_width="fill_parent"
    android:id="@+id/marquee"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:lines="1"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:text="@string/home"
    android:fontFamily="monospace"
    android:textStyle="bold"
    android:paddingBottom="20dp" />
</LinearLayout>

JAVA Code :

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView marqText  = (TextView)findViewById(R.id.marquee);
    marqText.setSelected(true);
}

Solution

  • Try adding android:singleLine = "true" to the TextView to keep the text on only one line.