2013-04-09 70 views
0

簡單的問題在這裏:我自定義一些按鈕,通過android:drawableLeft或Right在我的文本旁邊放置一個圖標,但我似乎無法找到如何準確定義尺寸。我的圖像碰巧太大,並且出現了我的按鈕形狀。使用android時設置圖片的一面:drawable ____在按鈕中

呵呵,雖然我在它:android:drawableLeft允許將圖像放在文本的左側,但是如何確定距離文本的距離?在我的情況下,它會自動進入我的按鈕的最左端,而我的文本居中。其結果是一切,但很好!

謝謝!

+0

可以應用填充你的看法 – 2013-04-09 08:16:55

回答

1

我建議從this topic開始。

但是如何確定距文本的距離?

這裏有一個答案:

的android:drawablePadding可以用來指定圖像和按鈕文本之間的填充量。

Source

1

我想這會做的伎倆

使用android:drawablePadding結合android:paddingLeftandroid:paddingRight迫使文字和向內朝繪製按鈕的中心......

1

如果要定義drawable的精度大小,則應該使用Java代碼而不是android:drawableLeft

Drawable dw = getResources().getDrawable(R.drawable.ic); 
    dw.setBounds(0, 0, 100, 100); // set the size of the drawable to 100*100 

    button.setCompoundDrawables(dw, null, null, null); 

因爲

android:drawableLeft // equals with setCompoundDrawablesWithIntrinsicBounds 

android:drawablePadding // this used to control the padding between the text and drawable