Thank you all!

It was hard to understand because I was assuming the home screen
always had to have 4x4 cells. But my assumption was not correct. A
480x800 mdpi would probably have more cells, maybe 6x6 or 6x7 (in
portrait).


On 17 jan, 15:51, Henrik Lindqvist <henrik.lindqv...@gmail.com> wrote:
> This is how I calculate the AppWidget size:
>
>   protected Point getAppWidgetPixelSize (AppWidgetProviderInfo
> appWidgetInfo, Point point) {
>     int cx = (appWidgetInfo.minWidth  + 2) / 74;
>     int cy = (appWidgetInfo.minHeight + 2) / 74;
>     float density = getResources().getDisplayMetrics().density;
>     switch (getResources().getConfiguration().orientation) {
>       case Configuration.ORIENTATION_PORTRAIT:
>         point.x = (int)( 80 * cx * density + .5f);
>         point.y = (int)(100 * cy * density + .5f);
>         return point;
>       case Configuration.ORIENTATION_LANDSCAPE:
>         point.x = (int)(106 * cx * density + .5f);
>         point.y = (int)( 74 * cy * density +.5f);
>         return point;
>       //case Configuration.ORIENTATION_SQUARE:
>       //case Configuration.ORIENTATION_UNDEFINED:
>       default:
>         throw new IllegalStateException("orientation");
>     }
>   }
>
> On Jan 17, 5:54 pm, Cleverson <clevers...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm trying to understand how the home screen calculates how many cells
> > will be assigned to a given widget. I came across the following
> > sentence in the Android Developer Site:
>
> > "Because the Home screen's layout orientation (and thus, the cell
> > sizes) can change, as a rule of thumb, you should assume the worst-
> > case cell size of 74 pixels for the height and width of a cell.
> > However, you must subtract 2 from the final dimension to account for
> > any integer rounding errors that occur in the pixel count. To find
> > your minimum width and height in density-independent pixels (dp), use
> > this formula:
> > (number of cells * 74) - 2
> > Following this formula, you should use 72 dp for a height of one cell,
> > 294 dp and for a width of four cells."
>
> > What if I have a mdpi (160dpi) device whose resolution is 480x800?
>
> > In a mdpi device, each 1 dip stands for 1 pixel. So, if my widget is
> > 72dip x 294dip, it would take 72px x 294px in the mdpi device.
> > As far as I cound understand, in the example above, the widget would
> > not take 4 cells in this device. The device is 480 pixels wide and 294
> > pixels would be covered by 3 cells.
>
> > Who's wrong here? The formula or my interpretation?
>
> > Thanks in advance!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to