當我點擊按鈕時,我想要一個按鈕上的背景圖像。為此我使用了以下方法。Button button=findViewById(R.id.button_00);
button.setBackgroundResource(R.drawable.jerry);當我點擊按鈕時背景圖像確實出現了。但是圖像比按鈕大。告訴我如何解決這個問題。
1 回答

慕后森
TA貢獻1802條經驗 獲得超5個贊
很好,您將 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" />
您也可以設置圖像運行時
ImageButton button=findViewById(R.id.button_00);
button.setImageResource(R.drawable.jerry);
添加回答
舉報
0/150
提交
取消