Reputation: 61
Is there any way to calculate home widget width at runtime. I want to add variable number of items(imageviews) based on it's width ,so I want to calculate widget's width in dp.
Upvotes: 1
Views: 295
Reputation: 199805
API v16 (4.1) adds a onAppWidgetOptionsChanged callback and as per the App Widget guide:
This is called when the widget is first placed and any time the widget is resized. You can use this callback to show or hide content based on the widget's size ranges. You get the size ranges by calling getAppWidgetOptions(), which returns a Bundle that includes the following:
OPTION_APPWIDGET_MIN_WIDTH—Contains the lower bound on the current width, in dp units, of a widget instance.
OPTION_APPWIDGET_MIN_HEIGHT—Contains the lower bound on the current height, in dp units, of a widget instance.
OPTION_APPWIDGET_MAX_WIDTH—Contains the upper bound on the current width, in dp units, of a widget instance.
OPTION_APPWIDGET_MAX_HEIGHT—Contains the upper bound on the current width, in dp units, of a widget instance.
Unfortunately, there is no clean alternative for pre 4.1 devices.
Upvotes: 1