gpt4 book ai didi

java - 调整按钮上背景图像的大小

转载 作者:行者123 更新时间:2023-12-02 02:40:16 24 4
gpt4 key购买 nike

我想在单击按钮时在按钮上显示背景图像。为此,我使用了以下方法。

Button button=findViewById(R.id.button_00);
button.setBackgroundResource(R.drawable.jerry);

当我单击按钮时,背景图像确实出现。但该图像比按钮大。请告诉我如何解决此问题。

最佳答案

很好,您将按钮更改为 ImageButtons 并使用 android:src 而不是 android:background 例如:

<ImageButton
android:id="@+id/button_00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/jerry"
android:onClick="btn_click" />

您也可以设置图像运行时

ImageButton button=findViewById(R.id.button_00);
button.setImageResource(R.drawable.jerry);

关于java - 调整按钮上背景图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57183500/

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