2

So I read up on widget sizes and created a 250dpX72dp widget, expecting it to take up 4 columns by one row. On my 2.2 device it does indeed show as expected, but on my 4.2 device it suddenly takes up 4x2.

I thought the size per cell was calculated as (cells * 74) - 2.

The widget definition is as follows:

 <?xml version="1.0" encoding="utf-8"?>
 <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialLayout="@layout/widget"
    android:minHeight="72dp"
    android:minWidth="250dp"
   />
M. le Rutte
  • 3,525
  • 3
  • 18
  • 31

1 Answers1

3

You need to apply a different formula starting from API 11; according to the documentation its (70 * n) - 30; so that would mean you should set the minHeight to 40. You can create two resources for the height in different resource folders (being values and values-v11), that way you can specify the height according to the old formula in the values/<insert fancy name here>.xml and the height according to the new formula in values-v11/<insert fancy name here>.xml

Note that you should also take into account margins from API 15 up, which is done in a similar way: http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

There still seems to be a quirk with the sizing on newer devices though, where 250dp would take 3 columns instead of 4.

See also Appwidget size calculation

Community
  • 1
  • 1
MrJre
  • 7,082
  • 7
  • 53
  • 66
  • are you sure you should take into account margins from API 15, isn't it API 14? – Jose_GD Aug 05 '13 at 13:39
  • Also, you need to apply a different formula starting from API 14, not 11. Honeycomb APIs (11, 12 and 13) use the original formula, (74 x n) - 2 – Jose_GD Sep 18 '13 at 21:48