0

I am working on an application where I have some fonts for which I have to give particular size.

I have a document for guiding me for the font sizes for all the resolutions but in the document the unit of font is pts. To work in our XML's, I have to use the font size either in SP or in DP.

I have seen few calculator like AngryTools to for different unit conversions but its seem that they are not converting correctly.

2560x1440 : XXX-HDPI : 44pts == ? sp or dp

1920x1080 : XX-HDPI : 33pts == ? sp or dp

1280x720/960x720 : X-HDPI : 22pts == ? sp or dp

640x480 : X-HDPI : 15pts == ? sp or dp

470x320/426x320 : MDPI : 10pts == ? sp or dp

Please help me out with some formula or solution so that we I can move ahead.

4

1 回答 1

1

这可能会帮助你..

public float pixelToDip(Context paramContext, int paramInt)
{
    Resources localResources = paramContext.getResources();
    return TypedValue.applyDimension(0, paramInt, localResources.getDisplayMetrics());
}


public int pxToDp(int paramInt, Context paramContext)
{
    DisplayMetrics localDisplayMetrics = paramContext.getResources().getDisplayMetrics();
    return Math.round(paramInt / (localDisplayMetrics.xdpi / 160.0F));
}
于 2014-08-05T07:08:28.917 回答