Two or more marquee TextView run at the same time

Refer to the article "Implement auto scroll TextView in XML" to implement auto run marquee TextView. If more than one marquee TextView are included in a same layout, only one of them will run. To enable all run at the same time, call setSelected(true) method of the TextViews.

Two or more marquee TextView run at the same time


<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/marqueetext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="Hello AndroidCoding: http://lesapplication.blogspot.com/" />
<TextView
android:id="@+id/marqueetext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="Hello AndroidCoding: http://lesapplication.blogspot.com/" />

</LinearLayout>


package com.example.androidtext;

import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView marqueeText1 = (TextView)findViewById(R.id.marqueetext1);
TextView marqueeText2 = (TextView)findViewById(R.id.marqueetext2);
marqueeText1.setSelected(true);
marqueeText2.setSelected(true);
}

}


0 Response to "Two or more marquee TextView run at the same time"

Posting Komentar