2

I want the text in a button to scroll...so for this i am using Text View on the button. I have set following attributes in the layout. but it's not working. I am using this in a RelativeLayout...can anyone tell me whats wrong with my code?

<TextView
    android:id="@+id/textView1"
    android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget" 
    android:layout_width="wrap_content"
    android:singleLine="true" 
    android:ellipsize="marquee"
    android:marqueeRepeatLimit ="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true" 
    android:scrollHorizontally="true"
    android:layout_height="wrap_content"/>

I got solution and i am sharing this ...i created a class

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class ScrollingTextView extends TextView {

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

    public ScrollingTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ScrollingTextView(Context context) {
        super(context);
    }
    @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;
    }

}

as I needed more then one TextView to be scrolled on a screen... next in layout.xml file used this....

<com.yourpackage.ScrollingTextView
        android:id="@+id/TextView01"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:padding="5dip"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="1.option" />

and voila....it's done

Matthieu
  • 16,103
  • 10
  • 59
  • 86
Nipun David
  • 29
  • 1
  • 3
  • possible duplicate of [Is there a way to make ellipsize="marquee" always scroll?](http://stackoverflow.com/questions/1827751/is-there-a-way-to-make-ellipsize-marquee-always-scroll) – Sam Nov 27 '12 at 07:49
  • I got the solution of this problem.... – Nipun David Nov 27 '12 at 11:28

1 Answers1

0

Make a class that extend textView as you need scroller on more then one textveiw

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class ScrollingTextView extends TextView {

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

    public ScrollingTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }



    public ScrollingTextView(Context context) {
        super(context);
    }
    @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;
    }

}

now use this class to make your text views volla its done

 <com.yourPackage.ScrollingTextView
        android:id="@+id/TextView"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button4"
        android:layout_alignTop="@+id/button4"
        android:layout_marginLeft="18dp"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:padding="5dip"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="Text"
        android:textColor="#000000" />
Nipun David
  • 273
  • 2
  • 12