Android TextView Marquee not working

Marquee does not work for my TextView. Please check the code below

Xml code forTextView

                          <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 action OnCreate

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

Thanks at Advance

+4
source share
6 answers

Since the text is very long and your code will only work if you write the text on one line. Or add

 android:singleline="true" 

in xml or change java code to.

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

This will definitely work for you.

+6
source

add this attribute to xml file

android:focusable="true"    
android:focusableInTouchMode="true" 
+1
source

"match_parent" (, 200dp... ..). setSelected true, , match_parent xml, .

xml:

                     <TextView
                        android:id="@+id/mtextcash"
                        android:layout_width="match_parent"
                        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" />

, match_parent, , , .

xml- android: maxLength = "5" , 5 , 50dp .

+1

, , marquee , , . .:)

 <TextView
        android:id="@+id/mywidget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:singleLine="true"
        android:textColor="#2086CA"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
        android:textAppearance="?android:attr/textAppearanceSmall" />

, .:)

+1

, TextView -

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

Selected (true):

 my_TextView.setSelected(true);
0
<TextView android:id="@+id/mtextcash"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:ellipsize="marquee"
                   android:gravity="center"
                   android:marqueeRepeatLimit="marquee_forever"
                   android:scrollHorizontally="true"
                   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" />
0

Source: https://habr.com/ru/post/1666574/


All Articles