How to create a Scrolling Text (marquee) in android using TextView?
OK At first we will create the XML that contains a TextView.
marqueetext.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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:layout_height="wrap_content" />
</RelativeLayout>
Now the java code
package com.example.marqueetext;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class Marqueetext extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.marqueetext);
TextView tv = (TextView) this.findViewById(R.id.TextView03);
tv.setSelected(true); // Set focus to the textview
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.marqueetext, menu);
return true;
}
}
Note : The XMl alone will not create the marquee. For that the most important thing is to do this in java code.
tv.setSelected(true); // Set focus to the textview
Now run the project and see the result.


Link to this post!