Android TextView Marquee not working

Yogesh Borhade picture Yogesh Borhade · Jan 12, 2017 · Viewed 7k times · Source

Marquee not working for my TextView Please check below code

XML Code for TextView

                          <TextView
                            android:id="@+id/mtextcash"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="30dp"
                            android:ellipsize="marquee"
                            android:fadingEdge="horizontal"
                            android:gravity="center"
                            android:marqueeRepeatLimit="marquee_forever"
                            android:maxLength="5"
                            android:scrollHorizontally="true"
                            android:scrollbars="horizontal"
                            android:singleLine="true"
                            android:text="Simple application that shows how to use marquee, with a long text"
                            android:textColor="@color/white"
                            android:textColorHint="@color/white"
                            android:textSize="25dp" />

In Activity OnCreate

TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash);
inputAvailableCash.setSelected(true);

Thanks in Advance

Answer

Vipin NU picture Vipin NU · Jan 12, 2017

Since the text is very long and and your code will only work if you write the text in single line. Either add

 android:singleline="true" 

in xml or change your java code to.

  TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash);
        inputAvailableCash.setSelected(true);
         inputAvailableCash.setSingleLine(true);

This will surely work for you.