0

我为我的应用程序制作了一个背景,其中包括两个图像。第一个高度为 480px;第二个应该显示在第一个的底部。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap
        android:src="@drawable/bg_top"
        android:tileMode="repeat" />
    </item>
    <item
        android:top="480px">
      <bitmap
            android:src="@drawable/bg_bottom"
            android:tileMode="repeat" />
    </item>
</layer-list>

但这在我的智能手机上不起作用 - 它解释了 px 错误(实际上看起来顶部值大约是 200px)
我知道建议使用 dp,但是如何将此 px 值转换为 dp?我无法以编程方式执行此操作,因为它保存在 xml 文档中。

4

2 回答 2

0

这可能在默认文件夹 (mdpi) 上,所以如果您需要 480px 并且它适用于 xhdpi,那么您可以将其设置为 240dp。

于 2013-05-29T18:38:40.893 回答
0
    px
    Pixels - corresponds to actual pixels on the screen.

    in
    Inches - based on the physical size of the screen.
    1 Inch = 2.54 centimeters

    mm
    Millimeters - based on the physical size of the screen.

    pt
    Points - 1/72 of an inch based on the physical size of the screen.

    dp or dip
    Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

    sp
    Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
于 2014-01-10T13:18:52.820 回答