的Nexus 7和Kindle Fire的高清,认为不同的不同、Kindle、Nexus、高清

2023-09-05 07:46:21 作者:我有我的Feel

我正在开发平板7英寸的Kindle Fire HD和Nexus 7的应用程序。 这两种应用是相同的尺寸和相同的屏幕分辨率。不过,我跑我的应用程序,这是很大的不同。为什么呢?

I'm developing an application for tablet 7 inch Kindle Fire HD and Nexus 7 . These two applications are the same size and the same screen resolution. However, I run my application, it is very different. Why?

看来这是因为Nexus 7保护被检测为TVDPI,而Kindle Fire的HD是华电国际。 如何基于模型有一个相同的渲染1280 * 800?

it seems this is because the nexus 7 is detected as TVDPI, and the Kindle Fire HD is HDPI. How to have a same rendering based on a model 1280 * 800?

感谢您

推荐答案

嗯,看来你已经发现了为什么两个有分歧,那是因为他们报告不同密度的比例系数:

Well, it seems you've already discovered why the two have differences, it's because they report different density scale factors:

的Nexus 7:TVDPI:比例系数= 1.333 的Kindle Fire HD:华电国际:比例系数= 1.5

那么,为什么他们的报告不同,当他们在技术上具有相同的物理尺寸和分辨率?

中的核心问题确实存在,因为一个设备是一个谷歌播放设备(Nexus的),另一种是不(点燃)。有谷歌播放(和其他谷歌应用程序)的所有Android设备只能通过传递一种叫做兼容性测试套件(CTS),这验证了像这样的设置符合他们所提出的标准,这样做。该标准本身都记录在一个兼容性定义文件(CDD)每个版本。 这里是一个链接到CDD为Android 4.0 (第7.1节涉及的屏幕尺寸和密度)。上的CDD告诉一设备制造商,他们应该报告所述比例因子是数值最接近屏幕的实际的DPI,这实际上是TVDPI在这种情况下

The CORE issue actually exists because one device is a Google Play device (Nexus) and the other is not (Kindle). All Android devices that have Google Play (and other Google apps) can only do so by passing something called the Compatibility Test Suite (CTS), which verifies that settings like this one conform to the standards they have put forth. The standards themselves are documented in a Compatibility Definition Document (CDD) for each release. Here is a link to the CDD for Android 4.0 (Section 7.1 deals with screen size and density). The CDD tell a device manufacturer that they should report the scale factor that is numerically closest to the screen's actual DPI, which is in fact TVDPI in this case.

亚马逊的设备不使用任何谷歌的应用程序,其中包括谷歌播放。虽然它可能是在遵循同样的标准对他们最有利,它们不是由它们的约束,而常常不遵守。 TVDPI一种悄然进入每个人都当它出现了在了Nexus 7,但亚马逊会知道这件事,如果他们引用的CDD设计中。

Amazon devices do not use any Google applications, including Google Play. While it may be in their best interest to follow the same standards, they are not bound by them, and the often are not followed. TVDPI kind of snuck up on everyone when it showed up on the Nexus 7, but Amazon would have known about it if they referenced the CDD during design.

如何做到这一点导致他们表现不同?

的区别并不在你的布局选择。显然,从你的截图两个器件都拿起适当的布局,你期望他们。在布局目录更改软件值只影响该设备将选择的布局...它不会改变对事情怎么会是规模东西。不要打扰试图把自己的布局密度特定的目录...布局应该是灵活的。

The differences aren't in your layout selection. Obviously from your screenshots both devices are picking up the proper layout as you expect them to. Changing the sw value on a layout directory only affects which devices will select that layout...it doesn't change anything about how things will be scale. Don't bother trying to place layouts themselves in density specific directories...layouts are supposed to be flexible.

相反,问题在于任何尺寸或大小的计算作出密度无关的像素单元(即畅游,或DP),如文本大小,您可能已经创建的任何固定视图大小,并绘制大小。

Instead the problem lies with any dimension or size calculation made on density-independent pixel units (i.e. dip or dp), such as text sizes, any fixed view sizes you may have created, and drawable sizes.

由于这两款器件具有的选择以不同比例的资产,你用你的DP定义任何可绘制的资源或任何值将导致一个小的变化。我给大家举两个例子:

Because these two devices have chosen to scale assets differently, any drawable resource you use or any value you define in "dp" will result in a small change. Let me give you two examples:

您定义的文本大小为的TextView 16DP 。在的Nexus 7,这将绘制文本的21px。 Kindle Fire的HD会得出相同的文本在24PX。差小......但它的存在。

You define the text size for a TextView to be 16dp. On the Nexus 7, this will draw the text at 21px. The Kindle Fire HD will draw that same text at 24px. The difference is small...but it exists.

也是如此为可绘制的图像。如果只定义了图像绘制-MDPI 在48×48和绘制 - 华电国际时的72x72,在相同的图像点燃具有72px图像直接使用,和Nexus将创建一个尺度64PX图像,所以有8个像素的两种资产之间的差

The same is true for drawable images. If you only defined an image in drawable-mdpi at 48x48 and the same image in drawable-hdpi at 72x72, the Kindle has a 72px image to use directly, and the Nexus will create a scale 64px image, so there's a difference of 8 pixels between the two assets.

我能做些什么使这两个看起来更相似?

在大多数情况下,我会说你不应该。典型的做法不会在很大程度上影响申请结果,除非布局的约束设置了太多的硬件codeD尺寸的缩放。

In most cases, I would say you shouldn't. Typically the scaling done does not largely affect the outcome of the application unless the constraints of the layout are set up with too many hard-coded sizes.

但是,一般来说,如果有你的用户界面的部件,需要专门改变用于此目的,该解决方案是定义的特定资源和尺寸为 -tvdpi 情况下,你觉得他们是必需的(再说一次,我不会推荐结垢一切都在你的应用程序,以满足这种情况下)。

However, in general if there are parts of your UI that you need to specifically change for this purpose, the solution is to define specific resources and dimensions for the -tvdpi case where you feel they are required (again, I wouldn't recommend scaling EVERYTHING in your app to meet this case).

有关的东西,如文本或视图的大小,这意味着你可能需要一个值-tvdpi / dimensions.xml 文件和缺省的值/尺寸的.xml 文件。使用上面的例子,你可以定义默认文本大小16DP,但在 -tvdpi 的位置,确定尺寸相同18dp。这将导致两个设备最多缩放最后文本24PX。在您的code,而实际尺寸时,其引用为 @扪/ myTextSize ,而不是 16DP 直接。

For things like text or view sizes, it means you may want a values-tvdpi/dimensions.xml file and a default values/dimensions.xml file. Using the example above, you could define the default text size as 16dp, but in the -tvdpi location, define the same dimension as 18dp. This will cause both devices to scale the final text up to 24px. In your code, where the actual dimension is used, reference it as @dimen/myTextSize rather than 16dp directly.

有关绘制项目,添加一个绘制-tvdpi 目录和扩展这些资产来匹配你是怎么想的,他们应该利用设备如的Nexus 7,再次与我们的previous例如,从复制相同的图像文件,绘制,华电国际文件夹到绘制-tvdpi 文件夹,以便两个设备也会得出同样的形象72px。

For drawable items, add a drawable-tvdpi directory and scale those assets to match how you think they should draw on devices like the Nexus 7. Again with our previous example, copy the same image file from the drawable-hdpi folder into the drawable-tvdpi folder so both devices will draw the same image at 72px.

要避免在多个地方复制相同的资产,你也可以做到这一点用别名。把图像本身为绘制/ 有一个特别的名字,并使用值-tvdpi / drawables.xml 值,华电国际/ drawables.xml 引用单一资产在两个地方。有关别名的详细信息,请看到这个文档。这些例子是布局,但同样的模式适用于可绘(或任何资源),通过改变 TYPE =绘制

To avoid copying the same asset in multiple places, you can also do this with aliasing. Putting the image itself into drawable/ with a special name, and using values-tvdpi/drawables.xml and values-hdpi/drawables.xml to reference the single asset in two places. For more information on aliasing, see this documentation. The examples are for layouts, but the same paradigm works for drawables (or any resource) by changing to type="drawable".