Rotate ImageView in widget

谁都会走 提交于 2019-12-08 06:53:09

问题


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.

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


回答1:


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).

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

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



来源:https://stackoverflow.com/questions/5971401/rotate-imageview-in-widget

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