且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

对方向变化更新的应用程序插件

更新时间:2023-01-25 21:48:49

回答我的问题。以正确的方式是不检测方向改变(其可以或可以不使用由归属发射器),但可以有自动适应取向变化的部件。有时它是平凡的,有时不是。在我的情况下,例如我需要显示的一道风景线位图和一个画像。通过有两个ImageViews,一个是使能(通过样式资源)的肖像和其他景观解决它。在AppWidgetProvider我填充两个图像(在我的案件档案URI),并让发射挑它需要的方向。

Answering my own question. The right way is not to detect orientation change (which may or may not used by the home launcher) but to have a widget that adapts automatically to orientation change. Sometimes it is trivial, sometimes it is not. In my case for example I needed to show one bitmap for landscape and one for portrait. Solved it by having two ImageViews, one that it is enable (by style resource) in portrait and the other in landscape. In AppWidgetProvider I populate the two images (file URI in my case) and let the launcher to pick the orientation it needs.

要了解在设备方向的变化,小部件的容器重新创建布局(正常应用资源选择规则)和重放上的布局RemoteViews命令是很重要的。

It is important to understand the upon device orientation change, the widget container recreates the layout (applying normal resource selection rules) and replay the RemoteViews commands on that layout.