Jomia
Jomia

Reputation: 3404

Android : How to display more than one Marquee simultaneously (focus for two marquees)

I want 2 marquees in my application. But only one is working always. If i comment the first one, then the second one will work. Otherwise the first one. Or only one marquee is getting focus at a time. If we press the down arrow, then the second one will get focus. How can both of these marquees get focus?

How can I display 2 marquees at the same time? Following are my code :

 <RelativeLayout 
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:id="@+id/imgLogotb">

      <TextView 
                    android:id="@+id/txt1" 
                    android:layout_width="wrap_content" 
                    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:layout_height="20dip"
                    android:singleLine="false"
                    android:ellipsize="marquee"   
                    android:marqueeRepeatLimit="marquee_forever"
                    android:scrollHorizontally="true" 
                    android:focusable="true" 
                    android:focusableInTouchMode="true" 
                   android:freezesText="true">
     </TextView>

     <TextView 
                    android:id="@+id/txt2" 
                    android:layout_width="wrap_content" 
                    android:text="START | lunch 1.00 | Dinner 2.00 | Travel 3.00 | Doctor 4.00 | lunch 5.00 | Dinner 6.00 | Travel 7.00 | Doctor 8.00 | END" 
                    android:layout_height="20dip"
                    android:singleLine="false"
                    android:ellipsize="marquee"   
                    android:marqueeRepeatLimit="marquee_forever"
                    android:scrollHorizontally="true" 
                    android:focusable="true" 
                    android:focusableInTouchMode="true" 
                    android:freezesText="true">
      </TextView>
</RelativeLayout>

Please help me by giving the solution.... Thank you...

Upvotes: 4

Views: 2332

Answers (1)

N-JOY
N-JOY

Reputation: 7635

Now I found a patch, you might say, for myself. Marquee text works when it is in focus. now our aim is to bring focus on every textView at the same time.

For this we will make our own custom TextView component class, and will return always true in method isFocusable(). Here it goes:

public class ScrollingTextView extends TextView {

    @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 all you have to do is to add this TextView in your XML layout as follows.

<com.yourpackagename.ScrollingTextView
    android:text="LONG LONG LONG LONG text..................."
    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:layout_height="wrap_content" />

and it's done, you can add this TextView component as many times as you want in XML layout, and all the textView will marquee simultaneously.

Upvotes: 4

Related Questions