13

I've written a widget which is supposed to be 4x2 homescreen blocks. It's minheight and minwidth, with accordance to the current "App Widget Design Guidelines" page are

android:minWidth="250dp"
android:minHeight="110dp"

And a padding is applied from dimens.xml if the system version is below Ice Cream Sandwich

On my Nexus 4 (xhdpi, Jellybean 4.2.1), this widget is 4x2. On an emulator (hdpi, Gingerbread 2.3.3), this widget is 4x2. On my Nexus 7 however (hdpi, Jellybean 4.2.1), the widget is 3x2. I can't for the life of me figure out why or how to fix it. Any thoughts?

Nick
  • 6,900
  • 5
  • 45
  • 66

1 Answers1

11

Lars Vogel writes in this Home Screen Widget tutorial that:

As a calculation rule you should define the size of the widget with the formula: ((Number of columns / rows)* 74) - 2. These are device independent pixels and the -2 is used to avoid rounding issues.

Edit: apparently Vogel got it from the old Widget API documentation (scroll down past mid page to see reference).

Based on this measurement, for a 4 cells width and 2 cells height, use 294 x 146 dip:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="294dip" android:minHeight="146dip"
    android:updatePeriodMillis="0" android:initialLayout="@layout/some_layout" />
Gunnar Karlsson
  • 28,350
  • 10
  • 68
  • 71
  • As you said, 294x146 would be based on the outdated documentation. In accordance with the new docs I've used the correct measurements for a 4x2 widget based on the new documentation, and the widget registers as 4x2 on all devices except for my Nexus 7, where it registers as 3x2 – Nick Dec 23 '12 at 21:41
  • What happens on Nexus 7 if you use the old measurements? – Gunnar Karlsson Dec 23 '12 at 23:57
  • Well, I know that it will work, because I was using the old measurements on a previous version of these widgets. However, with the old measurements, a 1x1 toggle widget for example, was measuring as 2x2 on my Nexus 4. The new measurements are supposed to be for Ice Cream Sandwich and up where the OS applies its own padding. The Nexus 7 is running 4.2 and therefore should use the new measurements. I have a padding automatically applied to the widgets if the OS is detected to be 3.x or lower – Nick Dec 24 '12 at 04:57
  • 1
    You're doing everything according to the new guidelines. My answer only says how to fix it - keep the old measurements - but you knew that already. As for why this happens, my guess would be the Nexus 7's 'special' dpi of tvdpi is causing the issue but I'm afraid I don't know how to take that line of inquiry any further: https://plus.google.com/105051985738280261832/posts/6eWwQvFGLV8 – Gunnar Karlsson Dec 24 '12 at 05:24