Question

public class Crunk extends Activity {
    TextView textView = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crunk);
        Button button = null;

        button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Log.e("It's Clicked", "Don't Worry");
                textView.setText("SeeMe");
                textView.setEllipsize(TruncateAt.MARQUEE);

            }
        });
        textView = (TextView)this.findViewById(R.id.textView1);
        textView.setSelected(true);
        textView.setText("Waitin'....");
    }

This code just shows the text not the marquee effect.

Help me out getting the effect.

I want the text to show the effect when the button is tapped.

Still can't get the desired effect even though tried most of the things....

        <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" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="180dp"
    android:text="@string/TapMe" />

<TextView
    android:text="@string/SeeMe"
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="51dp"

    android:textAppearance="?android:attr/textAppearanceLarge" />

Was it helpful?

Solution 3

Try following code in your onClick() of Button:

    button = (Button)findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Log.e("It's Clicked", "Don't Worry");

            textView.setText("Simple application that shows how to use marquee, with a long ");
            textView.setEllipsize(TruncateAt.MARQUEE);
            textView.setSelected(true);
            textView.setSingleLine(true);
        }
    });

as you have set in textView.setText("SeeMe"); is small text then textView's width.

OTHER TIPS

You can set these properties in your layout.xml

android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"

Set all the require three things (ellipsize, selected, and singleLine):

TextView tv = (TextView)findViewById(R.id.someTextView);
tv.setSelected(true);
tv.setText("Simple application that shows how to use marquee, with a long ");       
tv.setEllipsize(TruncateAt.MARQUEE);
tv.setSingleLine(true):

Does your TextView R.id.textView1 has this property ?

android:singleLine="true"

Add to textview xml property......

    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:singleLine="true"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top