Search code examples
androidandroid-4.0-ice-cream-sandwichandroid-3.0-honeycombandroid-appwidgetandroid-2.3-gingerbread

Appwidget size calculation


It might be me, but when I calculate minimum app widget sizes according to the formula given on the android page I don't get the right widget widths; The formula is as follows:

width(n) = (70 x n) - 30

When I want to have a 5x1 widget, the correct width would be (5 * 70) - 30 = 320dp. However when testing this on a motorola Xoom it resolves to being a 4x1 widget. I've tested different values and 400dp seems good for 5x1 on the motorola xoom with Honeycomb, but then I'd test it on a regular Galaxy Tab with Gingerbread and then it resolves to a 6x1 (like one would expect).

So two questions here;

  • What difference between Gingerbread and Honeycomb am I overlooking?
  • Since I know ICS widget size no longer has padding between widgets, is there some rule of thumb here as well?

Solution

  • Not too many devices fully follow Google's advised formula. You're better off using several xml-xxx folders that can specify more accurate minWidth & minHeight that correspond to the varying screens & OSes.

    Right now I four solely based on OS:

    xml       // standard
    xml-v11   // Honeycomb grid
    xml-v14    // ICS's new extra padding
    xml-sw552dp-v14  // ICS tablet padding
    

    But as I fine tune, I may have to add a few new folders for particular dpis or screens.

    Quick update:

    Only some devices use automatic padding. Samsung & HTC have custom UIs that use full-width widgets, so they override the OS padding on their launchers.