安卓:不正确的尺寸与毫米或英寸尺寸的看法 [英] Android: Incorrect size for views with mm or inch dimensions

查看:116
本文介绍了安卓:不正确的尺寸与毫米或英寸尺寸的看法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有具有10mm的layout_height看起来对大多数设备正确的按钮,但比如LG擎天柱2X和摩托罗拉的Defy的按钮有大约一半的大小:

我检索到这些设备上DisplayMetrics信息,并在这里是一个简短的介绍:

  HTC Desire Z的:480×800,密度高,xdpi:254.0,ydpi:254.0
摩托罗拉Defy:为480x854,密度高,xdpi:96.0,ydpi:96.0
三星Galaxy S2:480×800,密度高,xdpi:217.71428,ydpi:218.49463
LG的Optimus 2X:480×800,密度高,xdpi:160.0,ydpi:160.0
 

正如你所看到的欲望Z和三星有一个合理的期待X / Y-DPI值。该DEFY和擎天柱交付我认为obsiously不正确的值是错误的大小的原因。

有没有其他的方法来解决硬件错误,除了这些设备创建单独的布局文件<?/ P>

抑或是建议不要使用毫米/的尺寸呢?

解决方案

您不应该使用毫米/大小声明UI的尺寸值。 不建议。为什么?由于跨设备也不会正确缩放。

推荐的方式做到这一点是使用DP / SP来衡量视图对象/字体大小。

阅读这篇文章:

更多资源类型 - 尺寸

I've got a button having a layout_height of 10mm which looks correct on most devices, but on for instance the Lg Optimus 2X and on the Motorola Defy the buttons have about half the size:

i retrieved the DisplayMetrics info on those devices and here's a short overview:

HTC Desire Z:       480x800, density : HIGH, xdpi: 254.0, ydpi: 254.0 
Motorola Defy:     480x854, density : HIGH, xdpi: 96.0, ydpi: 96.0
Samsung Galaxy S2: 480x800, density : HIGH, xdpi: 217.71428, ydpi: 218.49463 
LG Optimus 2X:     480x800, density : HIGH, xdpi: 160.0, ydpi: 160.0

As you can see the Desire Z and the Samsung have a reasonable looking x/y-dpi value. the defy and the optimus deliver obsiously incorrect values that I assume are the reason for the wrong size.

Is there any other way to get around that hardware bug except creating seperate layout files for those devices?

Or is it recommended not using mm/in sizes at all?

解决方案

You should not use mm/in size to declare the dimension value of the UI. It is not recommended. Why? Because it will not scale correctly across devices.

The recommended way to do that is using the dp/sp to measure view object/font size.

Read this article:

More Resource Types - Dimension

这篇关于安卓:不正确的尺寸与毫米或英寸尺寸的看法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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