You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在layer-list中修改Bitmap尺寸?适配Android 5.1启动屏

解决Android 12以下版本启动屏图标占满屏幕的问题

方案1:给Layer List的Item设置内边距

通过给包含图标的<item>标签添加内边距属性,限制图标的显示区域,该方式兼容API 21及以上版本。

修改后的splash_background.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/splash_background.xml -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Background color -->
    <item android:drawable="@color/black" />

    <!-- Background image or drawable -->
    <item
        android:left="100dp"
        android:right="100dp"
        android:top="100dp"
        android:bottom="100dp">
        <bitmap
            android:src="@drawable/spotify"
            android:gravity="center"/>
    </item>
</layer-list>

可根据需求调整100dp的数值,适配不同屏幕尺寸。

方案2:使用Inset Drawable包裹图标

通过<inset>标签作为图标的容器,设置内边距限制图标显示大小,该方式兼容所有API版本。

修改后的splash_background.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/splash_background.xml -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Background color -->
    <item android:drawable="@color/black" />

    <!-- Background image or drawable -->
    <item>
        <inset
            android:insetLeft="100dp"
            android:insetRight="100dp"
            android:insetTop="100dp"
            android:insetBottom="100dp">
            <bitmap
                android:src="@drawable/spotify"
                android:gravity="center"/>
        </inset>
    </item>
</layer-list>

额外优化:提供多密度图标资源

为避免图标模糊,请在对应密度的资源文件夹中放置适配尺寸的图标:

  • drawable-mdpi:48×48px
  • drawable-hdpi:72×72px
  • drawable-xhdpi:96×96px
  • drawable-xxhdpi:144×144px
  • drawable-xxxhdpi:192×192px

不同分辨率的设备会自动加载匹配的图标,保证显示清晰。

内容的提问来源于stack exchange,提问作者Fatima Jamal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 13:27:20