在小部件旋转的ImageView部件、ImageView

2023-09-06 19:12:26 作者:ら用生命回忆从前

我创建一个小部件,我需要一个旋转ImageView的。该ImageView的驻留内侧从而在一个远程视窗中描述的布局。这可能吗?在我的正常应用程序的活动获得了使用findViewById()的ImageView的引用,然后调用setRotate(),但由于远程视窗不是一个活动findViewById()是不可用的。

I'm creating a widget where I need to rotate an ImageView. The ImageView resides insides a layout which in turn is described in a RemoteView. Is this possible? In my regular application Activity gained a reference to the ImageView using findViewById() and then calling setRotate(), but as RemoteView isn't an activity findViewById() isn't available.

我可以看到,它已经在这个应用程序之前完成:的https:/ /market.android.com/details?id=com.lanteanstudio.compass

I can see that it has been done before in this app: https://market.android.com/details?id=com.lanteanstudio.compass

推荐答案

如果您使用的是 RemoteViews ,那么你就不能直接更改可见视图本身,因为没有得到它的引用方式 - 一个 RemoteViews 对象一般运行在不同的进程(在主屏幕上的小部件的情况下,这是真的 - 小部件运行在主屏幕的过程,而不是你自己的)。

If you are using RemoteViews, then you cannot directly change the visible View itself, as there is no way of getting a reference to it -- a RemoteViews object generally runs in a different process (in the case of the widgets on the Homescreen this is true - the widgets run in the Homescreen process, not your own).

相反,你需要与图像旋转,创建一个新的RemoteViews - 你需要将其设置为前将旋转位图的的ImageView

Instead you need to create a new RemoteViews with the image rotated - you need to rotate the bitmap before setting it to the ImageView.

然后得到 AppWidgetManager 的一个实例,并调用 manager.updateAppWidget(appWidgetId,远程视窗)

Then get an instance of AppWidgetManager, and call manager.updateAppWidget(appWidgetId, remoteView).