Search code examples
androidmarquee

I can't get the marquee effect in Android even after trying all things


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


Solution

  • 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.