Photoshop design from px to dp
I've got a final app design made i Photoshop where everything is meas开发者_Python百科ured in PX. Now I realize that Android apps are using DP for font-sizes and other things.
Is there any way I can convert PX to DP ?
On a more practical note, you have a few choices in increasing work and fidelty:
Have your resources scaled for 160 dots per inch, put them in your
res/drawable
directory, and let the OS scale them to look right on the device.Make two copies of your resources: one at 160 dots per inch in your
res/drawable
and one at 240 dots per inch in yourres/drawable-hdpi
directory. Let the OS scale for the exact device starting from a pretty close number.Decide that you don't want any scaling and have raw pixels, so put your assets in the
res/drawable-nodpi
directory. This means that at 320x480 (pixel) graphic might be 2 inches by 3 inches on one phone but only 1 1/3 inches by 2 inches on another screen.Specify the exact scaling strategy for your work, using the
draw9patch
tool. This can be very useful for keeping the corners of boxes from getting the "jaggies" from scaling and for making full screen graphics cope with different aspect ratios.Make separate graphics for every device you care about and fall back on scalable graphics for the rest. You will need to outrun zealots waving style guides trying to convince you not to do it this way.
Oh, and as a gotcha, specify sp
for your fonts, instead of dp
or pt
. A 10 point font would be a 22 sp font [ =10 * (160/72) or = number of points times 2.222]. sp
units scale with user preferences for small, medium, or large fonts.
From this list of the dimension units supported by Android, here's a description of DP:
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
This means that the "conversion" between pixels and DP will not be consistent -- on some devices, the ratio might be 1DP = 160px, but it could theoretically be anything. This is all well and good when you're setting the width of a button to, say, 100dp
(since it will get rendered dynamically), but it presents a problem when you have images which must have a fixed size.
Read this page on "Supporting Multiple Screens" -- Android has something called resource directory qualifiers, which let you create size- and density-specific versions of your image resources. For example, for low-density screens, you could create a smaller version of your image and place it in the drawable-ldpi
directory (or drawable-hdpi
for high-density screens).
tl;dr You can't practically "convert from PX to DP" (since the ratio is not fixed), but you can create multiple versions of your images and tell Android which to use with resource directory qualifiers.
A pixel is PX and the DP or DIP are device independent pixels. I don't think that you need to convert these. But you can use scalable 9patch images using the draw9patch
tool from the android tools.
I have same issue but now got the Solution.
Why you not use the online convertor to see which dp or px you have to for different resolution of android device ??
See this link: this link which helps me a lot and also helps you.
Enjoy coding.
This is a online DP/PX Converter tools: http://labs.rampinteractive.co.uk/android_dp_px_calculator/
精彩评论