Hi,

thank you, it seems like something I needed - but is it really safe to use? 
I have tried it on my phone and it's ok, but will it correctly calculate 
actual size of the widget for all the different types of phones? 

I need to calculate the width of the widget, because I want to draw a 
horizontal line on it.  Length of this line depends on information, which 
I'm downloading from the web. If the informaton is "100 %", the length 
should be exactly the width of the widget, if "50 %", it should end in the 
middle, if "10 %", i will display just a short line...

It seems to me like this is the only possible solution for getting the 
actual width of the widget... If you can tell me your experiences with 
using this method on different devices, I will be very grateful.

Sofie

Dne pondělí, 17. ledna 2011 18:51:42 UTC+1 Henrik Lindqvist napsal(a):
>
> 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 <[email protected]> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to