I was happy to see support for resizable appwidgets arrive with Android 3.1, but I'm stumped on how to make them actually work.
I'm no appwidget novice, and have no problem adding
android:resizeMode="horizontal|v开发者_开发百科ertical"
to my appwidget definition XML. And that works as far as it goes, the widget is nominally resizable (long-press on it and handles appear that let me drag the border to different sizes).
Two problems, though:
First, it doesn't appear that my code gets called when the widget is resized. A breakpoint set in my onReceive()
handler never gets hit.
Second, assuming that I can get into my code, I can't see anywhere in the docs to get the current size of the widget. I'm already using calls to AppWidgetProviderInfo.minWidth
and .minHeight
, but those only reflect the minimum dimensions given in the XML, they don't change at runtime.
So, how is one meant to actually implement a resizable widget?
I am pretty sure there is no way to get the size of the widget below API 16 and there is no intent broadcast when the widget is resized below API 16.
From API 16 onAppWidgetOptionsChanged() was added and this is called when your widget is resized and you can retrieve the size of your widget from the Bundle passed to it.
精彩评论