Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textView marquee

I want to put a textView in homescreen, and I need the marquee effect

public class MainWidget extends AppWidgetProvider {
int a;
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;

String[] s={"woddfdfdfdfdfdffffffffffffffffffffffffffffffff","dd","ddd","ffff"};
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
      int[] appWidgetIds) {
      Timer timer = new Timer();
      timer.scheduleAtFixedRate(new WlanTimer(context, appWidgetManager), 100, 50000);
}

private class WlanTimer extends TimerTask {
        RemoteViews remoteViews;
        AppWidgetManager appWidgetManager;
        ComponentName thisWidget;

public WlanTimer(Context context, AppWidgetManager appWidgetManager) {

        this.appWidgetManager = appWidgetManager;
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.marketwidget_main);
        thisWidget = new ComponentName(context, MainWidget.class);
}

@Override
public void run() {
a=(int) (Math.random()*3);                            
        remoteViews.setTextViewText(R.id.TextView_marketwidget_main_marketmessage,s[a]);
    appWidgetManager.updateAppWidget(thisWidget, remoteViews);
    }
}
}

If i use s[0] instead s[a], it does not run, only "woddfdf" shows up.

My textView xml is:

 <TextView android:id="@+id/TextView_marketwidget_main_marketmessage"
    android:maxLines="1" android:focusable="true"
    android:ellipsize="marquee"
    android:inputType="text"
    android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:textColor="#ffffff" android:background="@android:color/transparent" android:layout_width="80dip" android:layout_height="20dip"></TextView>
like image 705
pengwang Avatar asked Dec 13 '25 22:12

pengwang


2 Answers

What I got from your question is, you want to show a scrolling marquee effect in TextView? If I am right, do the following.

Set android:ellipsize="marquee" in TextView element in your layout file (XML). Then, in your Activity's onCreate() method, add the line textView.setSelected(true);.

Note: Replace the name textView with the name of your TextView.

Revert back for any query.

like image 84
Mudassir Avatar answered Dec 16 '25 12:12

Mudassir


You can set the properties android:ellipsize="marquee" of textview. and hope this link would help you out if on using this property still not working: Ellipsize not working for textView inside custom listView

like image 24
Nikki Avatar answered Dec 16 '25 13:12

Nikki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!