首页 > 解决方案 > 在 Android 中将图像宽度和高度设置为其原始值的 50%

问题描述

我是 Flutter 开发人员,没有原生 Android 方面的经验。

我需要启动画面的图像是其大小的 50%。

假设图像分辨率为 120x120px,我希望它显示为 60x60px。

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="?android:colorBackground" />

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item>
</layer-list>

标签: javaandroidxmlkotlin

解决方案


如果您使用 API>23 并且虽然位图没有宽度和高度参数,您可以使用重力和项目宽度/高度来设置位图大小。

 <item
        android:width="60dp"
        android:height="60dp">
        <bitmap
            android:gravity="fill_horizontal|fill_vertical"
            android:src="@mipmap/launch_image" />
    </item>

推荐阅读