Android Widgets: Animations on RemoteViews ? [duplicate]

倖福魔咒の 提交于 2019-12-20 11:22:23

问题


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?


回答1:


  1. Create custom animation.
  2. Create ProgressBar and set in android:indeterminateDrawable your animation.
  3. Add ProgressBar to your widget layout and make it visible(invisible)


来源:https://stackoverflow.com/questions/4118233/android-widgets-animations-on-remoteviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!