如何你应该(不)在Android上使用密度无关的像素? [英] How should you (not) use density independent pixels on Android?

查看:263
本文介绍了如何你应该(不)在Android上使用密度无关的像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其中一张海报建议使用名为的 SDP ,作为关于Android的密度独立性机制的问题的答案。他辩解,称:

One poster suggested using a project called SDP, as an answer to a question regarding the Android density independence mechanism. He justified it, saying:

它可以帮助Android开发与支持多种屏幕

It can help Android developers with supporting multiple screens

这是为什么一个不好回答或一般一个坏主意?

Why is that a bad answer or a bad idea in general?

推荐答案

多种原因:

本项目采用的方法可以说是没用的,甚至具有破坏性。

The approach taken by this project is arguably useless, even destructive.

破坏性,因为它打破了Android的密度独立性。它需要需要小尺度以匹配每英寸属性显示器的实际像素的图像,因为它们被设计为该设备的广义密度。它扩展它们,甚至高达2.6倍<一href=\"https://github.com/intuit/sdp/blob/master/sdp-android/src/main/res/values-sw780dp/positive_sdps.xml\"相对=nofollow> 10平板电脑的。这必须引起模糊或像素化的位图。

Destructive, because it breaks Android density independence. It takes images that need little scaling to match the display's actual pixels per inch property, because they were designed for that device's generalized density. And it scales them up, even up to 2.6 times on 10″ tablets. This must result in blurry or pixelated bitmaps.

无用的,因为:

您不希望摆在首位较大的设备更大的物理尺寸反正。你不想把一个应用程序,只是规模上的一切更大的屏幕。这是苹果公司时所做的iPad第一在2010年出来,的人讨厌它的。

You don't want bigger physical size on bigger devices in the first place anyway. You don't want to take an app and just scale everything on bigger screens. This is what Apple did when the iPad first came out in 2010 and people hated it.

您的做什么的希望是把限制上的文字,按钮和不应过度伸展其他UI元素的宽度。您还需要更广泛的利润率。但你处理这个问题,通过为大屏幕,而不是由与Android是如何处理的屏幕密度摆弄提供一个替代布局。该文档同意我这一点。

What you do want is to put a limit on the width of text, buttons and other UI elements that shouldn't be stretched too much. You also want wider margins. But you handle this, by providing an alternative layout for large screens, not by fiddling with how Android handles the screen density. The documentation agrees with me on that.

如果你的真正的想一些图形是在大屏幕上更大的(你通常不应该,这里的第二个形象是完全正常的,除了横向拉伸),那么你应该通过为要支持各种规模/密度对提供可绘制处理。例如绘制,华电国际绘制-xhdpi 绘制-sw720dp - 华电国际绘制-sw720dp-xhdpi 。这种方式的位图将不需要缩放为那些更大的屏幕和将被显示在高品质。

And if you really wanted some graphic to be bigger on a large screen (which you generally shouldn't, the second image here is perfectly fine, except for the horizontal stretching), then you should handle it by providing drawables for every size/density pair that you want to support. For example drawable-hdpi, drawable-xhdpi, drawable-sw720dp-hdpi, drawable-sw720dp-xhdpi. This way the bitmap won't need scaling for those bigger screens and will be displayed in high quality.

借助截图不要使用相同的比例为每个设备。的Nexus 7看起来就像是微小的Nexus One。

The screenshots do not use the same scale for each device. Nexus 7 looks just as tiny as Nexus One.

在规模为preserved,比较看起来像这样使用项目时:

When the scale is preserved, the comparison looks like this when using the project:

用户界面是在Nexus

和这样的,当不使用它:

And like this, when not using it:

用户界面是物理两个设备上相同的大小,因为Android的处理密度独立和不受阻碍。

物理大小,而不是屏幕密度项目的交易。它所做的是根据不同的实际屏幕尺寸刻度单位。

That project deals with physical size and not screen density. What it does is scale units depending on varying physical screen size.

它并不适用于被问的问题。这可能是意译为如何推广Android的一个实际的屏幕密度?

It does not apply to the question that was asked. Which could be paraphrased as "How does Android generalize an actual screen density?".

这篇关于如何你应该(不)在Android上使用密度无关的像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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