1

I have trying to use marquee and its not working, Here is my code... can anyone see the problem?

 <TextView
        android:id="@+id/lblTitle" 

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

        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="15dp"
        android:gravity="center"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:text="Book Title"
        android:textColor="#FFFFFF"
        android:textSize="12dp" />

i set text of this textview at run time. i use code from this link TextView Marquee not working

Community
  • 1
  • 1
Youddh
  • 1,511
  • 4
  • 34
  • 51

6 Answers6

13

Just do this way in ur activity as ur code is ok for that for simple textview marquee

TextView textview=(TextView)findViewById(R.id.lblTitle);
textview.setSelected(true); 

and if u want to use marquee in listview in adapter than check answer given at Marquee in listview

Community
  • 1
  • 1
Khan
  • 7,585
  • 3
  • 27
  • 44
  • 1
    this is the solution. others don't work. The view must be set selected for marquee to work. NOTE that selected is different from focused. – Truong Nguyen Dec 17 '12 at 17:59
  • Is it possible to extend TextView and add it by default? for some reason it crashed for me when i tried to use "setSelected" in "setEllipsize" . – android developer Mar 16 '14 at 14:28
4
working on my phone 

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/lblTitle" 

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

            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="15dp"
            android:gravity="center"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text="Book Title sad ds sdas das asdas das asd asd sad as"
            android:textColor="#FFFFFF"
            android:textSize="12dp" />
    </LinearLayout>

enter image description here

Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
3

This code working for you.

<TextView
    android:text="START | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | END"
    android:id="@+id/MarqueeText" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:singleLine="true"
    android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true" 
    android:paddingLeft="15dip" 
    android:paddingRight="15dip" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:freezesText="true">
</TextView>

Thanks.

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37
  • I test it and it is working. another think without log text (test width must large then phone width) it is not wotking and aslo need android 1.5 and above – Md Abdul Gafur Jun 28 '12 at 07:37
1

This code works

<TextView
android:text="A very long book title"
android:id="@+id/book_title" 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:singleLine="true"
android:ellipsize="marquee" 
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true" 
android:paddingLeft="15dip" 
android:paddingRight="15dip" 
android:focusable="true" 
android:focusableInTouchMode="true" 
android:freezesText="true">
Bao Le
  • 16,643
  • 9
  • 65
  • 68
1

I've encountered the same problem. Khan's answer is right, but sometimes textview.setSelected(true); doesn't work when the text view can't get the focus all the time. So, to ensure TextView Marquee working, I had to use a custom TextView.

public class CustomTextView extends TextView {
    public CustomTextView(Context context) {
        super(context);
    }
    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    }


    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        if(focused)
            super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }

    @Override
    public void onWindowFocusChanged(boolean focused) {
        if(focused)
            super.onWindowFocusChanged(focused);
    }


    @Override
    public boolean isFocused() {
        return true;
    }
}

And then, you can use the custom TextView as the scrolling text view in your layout .xml file like this:

<com.example.myapplication.CustomTextView
            android:id="@+id/tvScrollingMessage"
            android:text="@string/scrolling_message_main_wish_list"
            android:singleLine="true"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit ="marquee_forever"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:scrollHorizontally="true"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@color/black"
            android:gravity="center"
            android:textColor="@color/white"
            android:textSize="15dp"
            android:freezesText="true"/>

NOTE: in the above code snippet com.example.myapplication is an example package name and should be replaced by your own package name.

Hope this will help you. Cheers!

David Roman
  • 421
  • 4
  • 11
0

This line of code is working 100%, Just put these lines inside your textview xml code, it will start works

 android:singleLine="true" 
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true" 
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81