I'm not having too much success applying animations to views inside a RemoteViews
.
For the sake of simplicity, let's say I have a widget with an ImageView
and a Button
. When clicking the button, I want to add a simple animation to the ImageView (a rotation for example).
Since I can't get a reference using findViewById()
like in an Activity
and RemoteViews
doesn't have a setter for an animation, I'm not sure what should I do.
I'm thinking of replacing the RemoteViews for the widget with a new layout, similar to the original but this one has the animation already loaded. Can I do this? Is it possible to embed an animation in a layout?
Code would be something like this for the WidgetProvider:
Intent intent = new Intent(context, RotateService.class); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.a_widget); views.setOnClickPendingIntent(R.id.a_button, pendingIntent); appWidgetManager.updateAppWidget(appWidgetId, views);
Then in RotateService:
ComponentName myWidget = new ComponentName(this, MyWidget.class); AppWidgetManager manager = AppWidgetManager.getInstance(this); RemoteViews newViews = buildNewRemoteViewsWithAnimation(); manager.updateAppWidget(myWidget, newViews);
Any other suggestion?
Long-press on an open section of your home screen to bring up the page settings. You should see an option that says "Widgets" or something similar (this will vary slightly depending on your Android version/skin/launcher)—tap on it, then scroll through the drawer until you find GifWidget.
android.widget.RemoteViews. A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.
Full update: Call AppWidgetManager. updateAppWidget(int, android. widget. RemoteViews) to fully update the widget.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With