开发者

How do I convert to DIP?

开发者 https://www.devze.com 2023-03-11 06:07 出处:网络
What is the formula for converting regular pixels to DIP? Assuming I have a photoshop document with a design in it that was intended for the Galaxy Tab (for example) which is 600x1024 actual pixels.

What is the formula for converting regular pixels to DIP?

Assuming I have a photoshop document with a design in it that was intended for the Galaxy Tab (for example) which is 600x1024 actual pixels.

What is the ratio between those and the DIP? I'm unclear on how Android translates this.

I want to use DIP (rather than pixels) so that it sc开发者_开发百科ales to look "ok" on other devices, but my primary concern is to get it pixel perfect in this resolution and my aim is to measure the position of an element in photoshop and then get an exact translation as to what the DIP needs to be for it to lay out identically on the Tab.


Their formula is somewhere in the docs:

 truePixels = DIPs * (device DPI / 160) 

Ah, there it is:

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

Taken from here.

0

精彩评论

暂无评论...
验证码 换一张
取 消