Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marquee not scrolling in android

I want to use the feature of marquee in my android app and am using this code for achieving the goal:

 <TextView
    android:id="@+id/marqueetext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:lines="1"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:text="hello all how are you"
    android:textColor="#ff4500" 
    />

MarqueeText = (TextView)ShowTheMessages.this.findViewById(R.id.marqueetext);
        MarqueeText.setSelected(true);

I don't know why it is not working.I have gone through many related posts but have not found the solution.Please help me.Thanks in advance.

like image 352
user1726619 Avatar asked Dec 15 '22 17:12

user1726619


2 Answers

change this line and try...

android:text="hello all how are you hello all how are you hello all how are you hello all how are you"
TextView txtView=(TextView) findViewById(R.id.marqueetext);
txtView.setSelected(true);

 <TextView
    android:id="@+id/marqueetext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:lines="1"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:text="hello all how are you hello all how are you hello all how are you hello all how are you"
    android:textColor="#ff4500" 
    />

or another example is...

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/marqueetext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:lines="1"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:textColor="#ff4500"
        android:text="hello all how are you hello all how are you hello all how are you hello all how are you hello all how are you" />
</RelativeLayout>
like image 103
Android Avatar answered Jan 09 '23 18:01

Android


android:singleLine="true"
android:ellipsize="marquee"

are the only required attributes and scrolling even works with layout_weight defined with layout_width=0dp

here is some sample code:

<TextView 
            android:id="@+id/scroller"
            android:singleLine="true"
            android:ellipsize="marquee"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#FFFFFF"
            android:text="Some veryyyyy long text with all the characters that cannot fit in screen, it so sad :( that I will not scroll"
            android:layout_marginLeft="4dp"
            android:layout_weight="3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            />

but the most important is TextView should get selected that you have already Done in your code.

hope it will help you out.

like image 31
Bhavesh Patadiya Avatar answered Jan 09 '23 19:01

Bhavesh Patadiya