简体   繁体   English

调整按钮背景图片的大小

[英]Resizing the background image on button

I want a background image on a button as I click on the button.for that I have used following aproach. 单击按钮时,我希望按钮上有背景图像。为此,我使用了以下方法。

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

background image do appear as I click on the button.but the image is too bigger than the button.Tell me how can i fix this problem. 单击按钮时会出现背景图像。但是图像比按钮大。请告诉我如何解决此问题。

It is good, you change the Buttons to ImageButtons and use android:src instead of android:background For example : 很好,将Buttons更改为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" />

You can set your image runtime as well 您也可以设置图像运行时

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM