使用层列表显示一些可绘制图像

Using layer-list to display some drawable images

Android studio 2.0 Preview 3b

您好,

我已经创建了以下布局,我想将其用作我的应用程序的背景。我正在使用 layer-list,我想在 2 个位置显示一碗豌豆。在预览中一切看起来都很好,但是当我 运行 在 genymotion 或一些廉价的中国设备上时,图像在屏幕上延伸。然而,在 Android AVD 上,一切看起来都很好,在我的 Nexus 5(真实设备)上一切正常。

这就是我想要的,这就是它在 AVD 和 Nexus 5 中的显示方式。如您所见,没有问题。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:centerX="0.5"
                android:centerY="0.3"
                android:endColor="#08e25b"
                android:gradientRadius="300dp"
                android:startColor="#b7e9c9"
                android:type="radial" />
        </shape>
    </item>

    <item
        android:width="48dp"
        android:height="48dp"
        android:left="350dp"
        android:top="400dp">
        <bitmap android:src="@drawable/peas" />
    </item>

    <item
        android:width="68dp"
        android:height="68dp"
        android:drawable="@drawable/peas"
        android:left="-20dp"
        android:top="480dp" />
</layer-list>

我已将 peas.png 文件放入 drawable-nodpi 并在 layer-list

中添加宽度和高度

当我 运行 使用 genymotion 和一些便宜的智能设备时,我得到以下信息:

Just quick summary.

Nexus 5 real device and AVD devices works ok
Genymotion and cheap smart devices doesn't display correctly

我只是对我应该相信什么感到困惑。我也尝试使用位图来查看是否会有任何不同。

非常感谢您的任何建议。

更新您的图层列表如下

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape>
            <gradient
                android:centerX="0.5"
                android:centerY="0.1"
                android:endColor="#08e25b"
                android:gradientRadius="300dp"
                android:startColor="#b7e9c9"
                android:type="radial" />
        </shape>
    </item>
    <item
        android:width="48dp"
        android:height="48dp"
        android:bottom="68dp"
        android:right="-20dp">
        <bitmap
            android:gravity="bottom|right"
            android:src="@drawable/peas" />
    </item>
    <item
        android:width="68dp"
        android:height="68dp"
        android:bottom="-20dp"
        android:left="-20dp">
        <bitmap
            android:gravity="bottom|left"
            android:src="@drawable/peas" />
    </item>
</layer-list>

将图像放入所有密度文件夹(xxhdpi、xhdpi、hdpi)。

系统根据屏幕分辨率选择图片资源。