gpt4 book ai didi

android - 如何转换为 DIP?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:28 25 4
gpt4 key购买 nike

将常规像素转换为 DIP 的公式是什么?

假设我有一个 photoshop 文件,里面有一个设计用于 Galaxy Tab(例如),实际像素为 600x1024。
这些与 DIP 之间的比率是多少?我不清楚 Android 如何翻译这个。

我想使用 DIP(而不是像素),以便它在其他设备上看起来“不错”,但我主要关心的是让它在这个分辨率下完美像素,我的目标是测量元素的位置在 photoshop 中,然后获得关于 DIP 需要什么才能在选项卡上以相同方式布局的准确翻译。

最佳答案

他们的公式在文档的某处:

 truePixels = DIPs * (device DPI / 160) 

啊,就是这样:

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.

取自here .

关于android - 如何转换为 DIP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6269004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com