Wednesday, 7 October 2015

Marquee effect in Android TextView


    Here I am  going to explain how to set Marquee effect in Android Text View.
                                           


Step 1).Mainactivity.java

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils.TruncateAt;
import android.widget.TextView;

public class MainActivity extends Activity {
private TextView textview;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview= (TextView) this.findViewById(R.id.textview);
textview.setSelected(true);

textview.setEllipsize(TruncateAt.MARQUEE);
textview.setSingleLine(true);
}

}

Step 2)activity_main.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:lines="1"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:text="***************Android Dhina Marquee  effect in textview ***************************** "
        android:textColor="#9bebe4" />

</RelativeLayout>

Happy Coding:)