user1726619
user1726619

Reputation: 941

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.

Upvotes: 4

Views: 7821

Answers (3)

Tale
Tale

Reputation: 76

Try

android:singleLine="true"

instead of

android:lines="1"

It's will solve your problem.

Upvotes: 1

Android
Android

Reputation: 2393

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>

Upvotes: 9

Bhavesh Patadiya
Bhavesh Patadiya

Reputation: 25830

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.

Upvotes: 3

Related Questions