I created a nice widet for my app. It just displays a list of items downloaded from a server. Well, to be precise, it only looks like a list, since ListView in RemoteViews is not supported in older android versions (which I want to support).
I want my widget to show a list of up-to-date items and I want these items to take all available widget space. To better show my problem, lest's assume WLOG that I want a widget with the TV schedule of selected programme. Knowing that:
How I can ensure that there will be no empty space at the bottom of the widget if the user will resize it to make it larger? I searched SO and it seems that when user will change widget size (on ICS or custom launcher - GO Launcher EX allows it) it will be impossible (Correct me if I'm wrong) to get widget's new dimensions.
But I don't really need them! I would like to know how many items will fit in the widget and calculating this from widget's size is just one of the methods.
So, I'm asking you if it's possible to, for example, receive notification if a remote view will become visible, or create custom view for use in RemoteViews which would somehow allow me to estimate the number of visible items.
If it won't be possible, I will just have to use some reasonable defaults, but it would be nice to know how many rows I can show.
Since Android 4.1 (API level 16) you can detect size changes with onAppWidgetOptionsChanged. Take a look at this answer for a simple example. With this callback at least you can track widget's size ranges (pity you cannot track actual widget sizes). With prior versions and custom launchers you're out of luck: AFAIK there's no generalized way to get actual widget size ranges, even less so an actual size.
What I would do in your case is to fill the widget with a number of views that fit in the default widget size, as defined in the appwidget provider. That way you avoid getting blank space at the bottom, unless there are actually few items to show, of course. When the widget gets resized, you can show more views using onAppWidgetOptionsChanged with API level 16 +, and with API level < 16 AFAIK you will get empty space, but in that case you could trigger a widget update soon to minimize this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With