具有动态大小的主屏幕小部件
是否可以动态创建主屏幕小部件(即无需在项目资源中定义固定布局)?
目前我有 4 个布局 - 但为了涵盖所有选项,我需要至少 15 个具有不同宽度/高度的不同布局,以填充用户的小部件选择器。
我更愿意在应用程序首选项中提供小部件设计,然后根据需要创建布局。
Is it possible to create a Home Screen widget dynamically (that is without defining a fixed layout in project resources)?
Currently I have 4 layouts - but to cover all options I'll need at least 15 different layouts with different width / height which fills up the widget selector for user.
I'd prefer to offer the widget design in App preferences then create layout as required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法更改小部件的大小,除非您使用的是运行 Android 3.1 (Honeycomb) 的平板电脑。否则,您必须将所需的所有尺寸指定为单个小部件。
关于所有不同的布局和填充的小部件选择器。您只需为每种尺寸添加一个条目。用户单击这些条目之一后,
您可以实现配置/选择活动(例如,就像您在 sense 中看到的那样,或者来自 google 的新闻和天气应用程序,您可以在其中选择包含天气、新闻或两者的布局)。
用户可以在那里为小部件选择布局。你只需要记住这个选择并
当小部件更新时设置正确的布局。您可以更改小部件布局
无论如何,在小部件更新函数内的RemoveViews构造函数内:
You can't change the widget size, unless you are on a tablet which is running Android 3.1 (Honeycomb). Otherwise you have to specify all the sizes you need as a single widget.
Regarding all the different layouts and the filled widget selector. You only have to add one entry there for every size. After the user clicks on one of these entries,
you can implement a configuration/select-activity (e.g. like you can see in sense, or the News&Weather app from google where you pick a layout with weather, news or both).
The user can pick a layout there for the widget. You just have to remember that choice and
set the correct layout when the widget is updating. You can change the widgets layout
inside the RemoveViews constructor that you have inside a widget update function anyway: