How to reverse the direction of marquee of a TextView
I figured out a very simple and easy way to do this. I made a marquee effect to move in both directions depending on our selection. So, here is the trick:
I used a TextView inside a HorizontalScrollView. I controlled its scrolling in a programmatic way. I got length of text using:
scroll_pos = (int)myTextView.getLayout().getLineWidth(0);
Then I used Handler and called it recursively until I reach the scroll limit. In this handler I made my HorizontalScrollView to scroll to a certain position:
Handler hHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
hScroll.scrollTo(scroll_pos, 0);
scroll_pos--;
if(scroll_pos >= 0)
hHandler.sendEmptyMessage(0);
}
};
And here it goes, a smooth marquee from Left to Right. Cheers!
Another simple way is using HTML and also you can change direction easily direction="Left"
<html><body><FONT COLOR="#000000" ><marquee id="mrqSlogan" direction="Left" style="width: auto;" >text your</marquee></FONT></body></html>
And Pass to WebView
webView.loadDataWithBaseURL(null, yourhtmltext, "text/html" , null, null);
Finally I found the BEST Solution here: https://github.com/Torob/MarqueeView
to use this library:
- simply add this java file (MarqueeView.java) to your project java folder
in your xml layout put your TextView inside of this MarqueeView like this:
<your.packagename.MarqueeView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/horizontalScrollView" android:scrollbars="none" android:visibility="visible" android:clickable="false"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/test" android:id="@+id/scrollingtext" android:singleLine="true" android:focusable="false" android:focusableInTouchMode="false" android:paddingRight="25dp" android:paddingLeft="25dp" /> </your.packagename.MarqueeView>