The + 0.5f is there to round up. All conversions in the platform are
done rounding up and you should do the same.

On Tue, Sep 7, 2010 at 2:14 AM, jerryfan2000 <[email protected]> wrote:
> Hi,
> I was reading multiple screen support page on SDK doc for solving a
> pixel to dpi scaling problem in my app. In the doc, it says
> "// Convert the dips to pixels
> final float scale =
> getContext().getResources().getDisplayMetrics().density;
> mGestureThreshold = (int) (GESTURE_THRESHOLD_DIP * scale + 0.5f);"
>
> My question is why we have to add 0.5f at the end? It indeed works
> great on high density screen but failed to match the result on medium
> density screen. For medium density screen, I have to remove the +0.5f.
> In addition. according to the doc, px - dpi conversion works like px =
> dpi x (density/160) and there is no mentioning of adding additional
> 0.5 at the end. Does anybody know why and how it works? Thanks.
>
> --
> 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
>



-- 
Romain Guy
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

-- 
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