对方向变化更新的应用程序插件 [英] Updating app widget on orientation change

查看:107
本文介绍了对方向变化更新的应用程序插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要活动和应用部件的应用程序。该应用程序部件需要每当屏幕方向的变化进行更新(它计算它的位图尺寸,这取决于当前的方向)。

I have an app with a main activity and an app widget. The app widget needs to be updated whenever the screen orientation changes (it computes its bitmap size and this depends on the current orientation).

我怎么可能会导致部件在方向变化更新?我发现ACTION_CONFIGURATION_CHANGED事件,但我不知道如何,因为文件说,它无法在清单中注册使用它。

How can I cause the widget to update on orientation change? I found the ACTION_CONFIGURATION_CHANGED event but am not sure how to use it since the documentation say that it cannot be registered in the manifest.

如果有帮助,我已经有一个BroadcastReciever,更新午夜的小部件。

If it helps, I already have a BroadcastReciever that updates the widget on midnight.

推荐答案

回答我的问题。以正确的方式是不检测方向改变(其可以或可以不使用由归属发射器),但可以有自动适应取向变化的部件。有时它是平凡的,有时不是。在我的情况下,例如我需要显示的一道风景线位图和一个画像。通过有两个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.

这篇关于对方向变化更新的应用程序插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆