2011-12-15 91 views
22

我想在文本和邊框之間的按鈕內有一些邊距,但我不知道如何指定它們。按鈕內邊距

我知道的唯一方法是使用android:layout_width =「...」,但這不是相對於文本大小。

謝謝!

+0

你想要的文字是在哪裏,文本大小必須單獨定義。 – 2011-12-15 09:08:05

回答

26

使用填充可以在按鈕中的邊框和文本之間添加邊距。

1

要測量其尺寸,視圖會考慮其填充。填充用視圖左側,頂部,右側和底部的像素表示。填充可用於將視圖的內容偏移特定量的像素。例如,左邊距2會將視圖的內容向左邊緣的右側推動2個像素。

閱讀更多的official doc

97

如果你正在尋找這種對這個厚臉皮文字的左側和右側的填充: enter image description here

這裏是你做了什麼。 :

<Button 
    android:id="@+id/she_was_good" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:soundEffectsEnabled="false" 
    android:layout_alignParentBottom="true" 
    android:paddingRight="25dp" 
    android:paddingLeft="25dp" 
    android:text="@string/im_sorry_lol_str" /> 

你正在尋找的部分是paddingRightpaddingLeft

+14

似乎「專業」意味着你需要失去幽默感。來自知道笑對自己的健康是有益的人... – WarrenFaith 2014-01-28 09:17:03