Home screen widget with dynamic size
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 t开发者_开发技巧he widget selector for user.
I'd prefer to offer the widget design in App preferences then create layout as required.
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:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
精彩评论