Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling Textview in android

In my application i have to implement an automatically scrolling textview, I referred this link .

Now I have a scrolling tetxview.But according to my requirement is that I have a string array(I have parsed and I have some string)..Consider the array may be

 string[] array=new string{"fgsdfd","gdfghdjhsd","gdfjhsgfhds"};

Now i want this array to be displayed in that textview(which will scroll automatically).

I want like this:

 fgsdfd   gdfghdjhsd    gdfjhsgfhds------------------>this will scroll automatically

This is my textview(scrolling):

 <TextView
    android:text="Really Long Scrolling Text Goes Here.... ..... ............ .... ...."
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:id="@+id/TextView03"
    android:padding="5dip" 
    android:layout_width="wrap_content" 
    android:textColor="#000000"
    android:layout_height="wrap_content" />

How can I set an array of string to a tetxview..Please help me.

like image 239
Subburaj Avatar asked Oct 06 '22 14:10

Subburaj


1 Answers

You can merge all of your string in one string by StringBuilder and apply it to the TextView.

I've implemented my own TextView with scrolling by wrapping textview (and maybe some other views)

private Runnable scrollRight = new Runnable()
{

    @Override
    public void run()
    {
                    // can control scrolling speed in on tick
        topScroll.smoothScrollBy(1, 0);
    }
};

and in new Thread I invoke:

while (!interruptScroll){
    try{
        Thread.sleep(50); // control ticking speed
    }
    catch (InterruptedException e){
        e.printStackTrace();
    }
    topScroll.post(scrollRight);
}

and by manually scrolling the scrollView i interrupt the scrolling (such an automatic scrolling while not interrupted by user).

like image 83
dilix Avatar answered Oct 10 '22 03:10

dilix