Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widget wrong grid size

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?

like image 500
Nick Avatar asked Dec 12 '12 07:12

Nick


1 Answers

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" />
like image 137
onosendai Avatar answered Nov 13 '22 06:11

onosendai