This question already has answers here:
Is there a way to animate on a Home Widget?
(5个答案)
4年前关闭。
我在将动画应用于
为了简单起见,假设我有一个带有
由于无法像
我正在考虑用一种新的布局替换该窗口小部件的RemoteViews,该布局与原始布局类似,但是已经加载了动画。我可以这样做吗?是否可以在布局中嵌入动画?
对于WidgetProvider,代码如下所示:
然后在RotateService中:
还有其他建议吗? 创建自定义动画。 创建ProgressBar并在android:indeterminateDrawable中设置动画。 将ProgressBar添加到小部件布局中,并使它可见(不可见)
(5个答案)
4年前关闭。
我在将动画应用于
RemoteViews
内的 View 方面没有取得太大的成功。为了简单起见,假设我有一个带有
ImageView
和Button
的小部件。单击按钮时,我想向ImageView添加一个简单的动画(例如旋转)。由于无法像
findViewById()
中那样使用Activity
来获得引用,并且RemoteViews
没有动画的 setter ,因此我不确定该怎么做。我正在考虑用一种新的布局替换该窗口小部件的RemoteViews,该布局与原始布局类似,但是已经加载了动画。我可以这样做吗?是否可以在布局中嵌入动画?
对于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);
然后在RotateService中:
ComponentName myWidget = new ComponentName(this, MyWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
RemoteViews newViews = buildNewRemoteViewsWithAnimation();
manager.updateAppWidget(myWidget, newViews);
还有其他建议吗?
最佳答案