如何在Layout中将PX转换为DP [英] How to convert PX into DP in Layout

查看:34
本文介绍了如何在Layout中将PX转换为DP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设计师给了我一个 PSD 文件,他为 1080X1920 分辨率创建了它

Designer has given me a PSD file, He has created it for 1080X1920 resolution

在PSD中他定义header高度应该是52pxSlider高度应该是350px等等在..

In PSD he defines that the header height should be 52px, Slider height should be 350px and so on..

在布局中,当我编写 layout_height=350dp 时,它占用了很多高度并覆盖了一半以上的屏幕.

In layout when i write layout_height=350dp its taking a lot of height and covering more than half of screen.

我使用默认布局来完成此任务.

I am using default layout to accomplish this task.

请指导我如何在DP的layout中定义Height相对于PX

Kindly guide me how to define Height in layout in DP with respect to PX

推荐答案

看起来缺少设计者-开发者流程.您获得的设计不适合移动设备(Android 和 iOS).我建议您查看一些工具以获得良好的工作流程.

Looks like there's a lack of designer-developer flow. The designs you were given are not mobile friendly (Android neither iOS). I recommend you to take a look to a couple of tools for a nice workflow.

草图

Zeplin

请大家阅读这篇文章:

DPI 设计师指南

在 Android 你需要在 dps 中工作并且你需要在 dps 中给出设计.如果您获得以像素为单位的设计,您必须与设计师达成一致,即 1px 等于 1dp,换句话说,设计师正在处理 MDPI 基础,其中 1dp 等于 1dp.

In Android you need to work in dps and you need the designs to be given in dps. In case you are given the designs in pixels you have to have the agreement with the designer that 1px is equals to 1dp, in other words, the designer is working on MDPI basis where 1dp is equals to 1dp.

因此,最简单的方法是您的设计师需要在 360x640 像素而不是 1080x1920 的屏幕上工作.现在您可以忘记将像素转换为 dps 了,反之亦然,因为 1px 对您来说就是 1dp.对于您的设计师来说也会更容易,因为他需要遵循 指南 到设计工具,他不再需要将 dps 转换为像素.每次他阅读指南中的 48 dps 时(无处不在)他知道他必须在设计工具的 360x640 画布中将其读取为 48 像素.

So the easiest way to go is your designer needs to work in a screen that is 360x640 pixels instead of 1080x1920. Now you can forget about translating pixels to dps and the other way around because 1px would be 1dp for you. For your designer as well will be easier because he needs to go from guidelines to the design tool, and he doesn't need to translate dps into pixels anymore. Everytime he reads 48 dps in the guidelines (which is everywhere) he knows he has to read it as 48 pixels in his 360x640 canvas in the design tool.

注意事项

360x640 是 dps 中常见的屏幕尺寸(Galaxy S5、Nexus 5 和许多其他产品),因此现在被用作参考.请意识到您的设计师无法为您提供每种设备每种布局尺寸中每个组件的确切尺寸.所以像工具栏高度(通常是 56dp)这样的东西很容易转换到每个设备上,但是你在他的设计中设置的工具栏宽度(如果你按照我的建议是 360)对你来说完全没用,因为这取决于真实的设备.Galaxy S5 和 Nexus 5 为 360,但 Nexus 4 为 384,nexus 6、6P 和 5X 为 413 左右……实际上还有更多!!

360x640 is a common screen size in dps (Galaxy S5, Nexus 5 and many others) and because of that is taken as a reference now a days. Please realize your designer can not give you the exact sizes for every component in every layout size for every device. So things like the toolbar height (usually 56dp) is easy to translate to every device, but the toolbar width that you'll size in his designs (360 if you follow my recommendation) is completely useless for you, because that depends on the real device. The Galaxy S5 and the Nexus 5 are 360, but the Nexus 4 is 384, and the nexus 6, 6P and 5X is around 413.... and actually there's much more!!

仅针对一种设备或一种屏幕尺寸进行设计过于简单且有问题.请注意,您必须开发响应式 布局准备好 多窗口.

Designing just for one device or one screen size is too simplistic and problematic. Be aware you have to develop responsive layouts ready for a multiwindow.

这篇关于如何在Layout中将PX转换为DP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆