Friday, February 22, 2013

Marquee effect in TextView tutorial


Here is the code

xml File

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
        android:id="@+id/mywidget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:lines="1"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:textColor="#ff4500"
        android:text="Simple application that shows how to use marquee, with a long text" />

java file 

?
1
2
3
4
5
6
7
8
9
10
public class TextViewMarquee extends Activity {
    private TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) this.findViewById(R.id.tv);  
        tv.setSelected(true);  // Set focus to the textview
    }
}

No comments:

Post a Comment