天天看點

android ImageButton的一些使用tip

android提供了android.widget.ImageButton控件,在使用該控件時,有以下兩點注意事項:

1、該控件預設帶有背景,是以如果不需要背景,需要手動将背景設為null

2、如果隻是将背景設為null,該控件的padding(比較大)依然存在,是以,必須手動設定padding或者設一張新的背景圖。

關于背景圖與padding的問題,其實幫助文檔有說明:

Set the background to a given Drawable, or remove the background. If the background has padding, this View's padding is set to the background's padding. However, when a background is removed, this View's padding isn't touched. If setting the padding is desired, please use 

setPadding(int, int, int, int)

.

繼續閱讀