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

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

问题描述

Designer给了我一个 PSD 文件,他以 1080X1920分辨率

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

在PSD中,他定义 高度应为 52px 高度应为 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.

请指导我如何相对于 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.

素描

齐普林

请同时阅读这篇文章:

DPI设计指南

在Android 中,您需要在dps中工作,并且需要以dps给出设计.如果您获得以像素为单位的设计,则必须与设计者达成一致,即1px等于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.对于您的设计师来说,也将变得更加容易,因为他需要阅读指南a>设计工具,他不再需要将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!!

仅针对一种设备或一种屏幕尺寸进行设计过于简单和成问题.请注意,您必须开发响应可以用于 multiwindow 的布局.

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.

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

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