PT和DP:机器人尺寸的区别 [英] Difference between android dimension: pt and dp

查看:193
本文介绍了PT和DP:机器人尺寸的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该文件说,160 DP(密度无关)等于1英寸。 72 PT也是1英寸。所以,我不明白为什么Android的定义DP测量,而它似乎工作一样点。任何人都可以解释一下吗?为什么要使用DP,如果我可以使用PT?

The documentation says that 160 dp (density-independent) equals 1 inch. And 72 pt is also 1 inch. So I don't see why android define a dp measurement while it seems to work the same as points. Can anybody explain that? Why should I use dp if I can use pt?

推荐答案

用于错误状态160 DP总是等于1英寸,无论屏幕像素密度的Andr​​oid的文件。这是报告为错误这是接受和更新的文档。

The Android documentation used to incorrectly state that 160 dp always equals 1 inch regardless of screen density. This was reported as a bug which was accepted and the documentation updated.

从更新的文档:

160 DP并不总是等于1英寸,它会与不同的屏幕大小和密度有所不同。在具有160dpi(MDPI)的密度的屏幕,160 DP将等于1英寸。

160 dp will NOT always equal 1 inch, it will vary with different screen sizes and densities. On a screen with a density of 160dpi (mdpi), 160 dp will equal 1 inches.

1分将始终等于1/72,无论画面的密度。

1 pt will always equal 1/72 in, regardless of the screen density.

Android的文档,这是<一个href="http://developer.android.com/guide/topics/resources/more-resources.html#Dimension">here.

The Android documentation for this is here.

更新:

我做了一个小的应用程序,试图验证不同的大小。它看起来像什么上面是正确的,至少在我的宏达咏叹调所示。下面是截图:

I made a small application to try and verify the different sizes. It looks like what is above is correct, at least when shown on my HTC Aria. Here is a screenshot:

这是有趣的是,这些尺寸并没有在Eclipse图形编辑器完全匹配。为dp和藻大小动摇根据屏幕的编辑器中的大小和分辨率。以下是编辑器的截图(左为2.7in QVGA滑块,右边是10.1in WXGA,裁剪):

It's interesting to note that these sizes did NOT match up exactly in the eclipse graphical editor. The dp and sp sizes wavered depending on the size of the screen and resolution in the editor. Here are some screenshots from the editor (left is 2.7in QVGA slider, right is 10.1in WXGA, clipped):

这将是有趣的,如果这些编辑器渲染匹配实际设备。任何人都可以验证这些大小?我会在下面附上万一有人想帮助我的XML。

It would be interesting to see if these editor renders match up with the actual devices. Can anyone verify these sizes? I'll attach my xml below in case anyone wants to help out.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:orientation="vertical">
    <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="22sp" android:padding="5sp" android:text="160dp"></TextView>
    <View android:id="@+id/view1" android:layout_height="20dip" android:layout_width="160dp" android:layout_marginLeft="20sp" android:background="#FF22FF22"></View>
    <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="22sp" android:padding="5sp" android:text="72pt"></TextView>
    <View android:id="@+id/view2" android:layout_height="20dip" android:layout_width="72pt" android:layout_marginLeft="20sp" android:background="#FF22FF22"></View>
    <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="22sp" android:padding="5sp" android:text="1in"></TextView>
    <View android:id="@+id/View01" android:layout_height="20dip" android:layout_width="1in" android:layout_marginLeft="20sp" android:background="#FF22FF22"></View>
    <TextView android:layout_width="wrap_content" android:textSize="22sp" android:layout_height="wrap_content" android:text="160sp" android:padding="5sp" android:id="@+id/TextView01"></TextView>
    <View android:layout_marginLeft="20sp" android:layout_width="160sp" android:id="@+id/View04" android:background="#FF22FF22" android:layout_height="20dip"></View>
    <TextView android:layout_width="wrap_content" android:textSize="22sp" android:layout_height="wrap_content" android:padding="5sp" android:id="@+id/TextView02" android:text="160px"></TextView>
    <View android:layout_marginLeft="20sp" android:id="@+id/View03" android:background="#FF22FF22" android:layout_height="20dip" android:layout_width="160px"></View>
    <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="22sp" android:padding="5sp" android:text="25.4mm"></TextView>
    <View android:id="@+id/View02" android:layout_height="20dip" android:layout_marginLeft="20sp" android:background="#FF22FF22" android:layout_width="25.4mm"></View>
</LinearLayout>

编辑:新增2个设备约翰的例子。在留下了三星Nexus S(OS 2.3.3)。在右边,一个三星Galaxy Tab 10.1(OS 3.1)。无器官功能障碍综合征。

Added 2 more devices to John's example. On the left a Samsung Nexus S (OS 2.3.3). On the right, a Samsung Galaxy Tab 10.1 (OS 3.1). No mods.

在了Nexus S,160dp比1英寸略大。所有的正常的物理单位(在,毫米,磅)都是相同的尺寸。我测用一把尺子,和160 DP酒吧是1mm左右比它应该更大。虽然物理单位1毫米短比他们应该。

On the Nexus S, 160dp is slightly larger than 1 inch. All the normal physical units (in, mm, pt) are all the same size. I measured it with a ruler, and the 160 dp bar is about 1mm larger than it should. While the physical units are 1mm shorter than they should.

在该选项卡,所有的酒吧都完全一样,和1毫米比我测量的尺子更长的时间。

On the Tab, all bars are exactly the same, and 1mm longer than what I measured with a ruler.

这篇关于PT和DP:机器人尺寸的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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