【问题标题】:Set Image Width & height to 50% of its original in Android在 Android 中将图像宽度和高度设置为其原始值的 50%
【发布时间】:2021-06-09 14:54:11
【问题描述】:

我是一名 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>

【问题讨论】:

    标签: java android xml kotlin


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,但我实际上想显示 50% 的大小,它不应该是硬编码
    猜你喜欢
    • 2013-02-06
    • 2014-04-26
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    • 2014-06-21
    • 2012-07-15
    • 2015-03-18
    相关资源
    最近更新 更多