开发者

How to resize a widget after it is selected from the widget menu

I am creating a widget and I want to be able to have the user select the size of the widget in a menu during the co开发者_运维技巧nfiguration activity. My problem is that in the appwidget-provider meta data xml, the block size is already set before the configuration activity is already entered. I need to be able to reset the info of the widget, which contains the block size (minHeight, minWidth), without having to add separate widgets of different sizes. Any ideas?


You cannot do this. It is an Android limitation. Create several widgets with different sizes, name them like "YourWidget (small)", "YourWidget (large)", etc. Or "YourWidget 1x1" and "YourWidget 2x1". You'll need several nearly identical appwidget-provider xml...

Since you'll need also nearly identical provider and configuration classes, define a base classes with all needed code there, and then inherit from them, something like this:

public class WidgetProvider2x1 extends WidgetProvider { @Override int getWidgetStyle() { return WidgetProvider.WIDGET_STYLE_2x1; }}

call getWidgetStyle() in the base class when you need to know the size of your widget.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜