gpt4 book ai didi

java - Android ImageButton 在调整大小时裁剪

转载 作者:行者123 更新时间:2023-12-01 08:03:25 26 4
gpt4 key购买 nike

我为我的应用程序创建了一些自定义按钮。我不想为同一图像创建不同图像尺寸的负载以进行屏幕优化。我试图缩小 XML 中的图像,但是当我将参数更改为:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/one_default" />

</RelativeLayout>

这就是我所看到的:

enter image description here

原来的样子:

enter image description here

如何在不裁剪图像的情况下缩小图像?

最佳答案

试试这个:

android:scaleType="fitXY"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:adjustViewBounds="true"

这会起作用,我刚刚尝试过;)

关于java - Android ImageButton 在调整大小时裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23461391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com