2012-02-18 86 views
1

我有這樣一個按鈕....Android:如何居中按鈕標題?

<Button 
     android:id="@+id/mark_button" 
     android:layout_width="wrap_content" 
     android:layout_height="33dp" 
     android:text="Note" 
     android:focusable="false" 
     android:gravity="center_horizontal|center_vertical" /> 

它有一個固定的大小,如果我測試的應用程序我的手機上的文字是沒有得到在按鈕的中心,所以文字的底部變切。看看這裏:Picture

你有什麼建議嗎?

+0

我用的是非標準,Android的按鈕...我想這固定大小! – JavaNullPointer 2012-02-18 14:32:22

+0

使用wrap_content的高度。而對於較小的按鈕使用屬性使用小尺寸。 – PravinCG 2012-02-18 14:34:04

+0

我認爲字體大小與您的固定高度相比太大了... – 2012-02-18 14:34:12

回答

1

使用wrap_content爲您的佈局高度和使用style="?android:attr/buttonStyleSmall"。 你會得到一個小按鈕,它的大小類似於你想要的大小:

你的代碼應該是這樣的:

<Button 
     style="?android:attr/buttonStyleSmall" 
     android:id="@+id/termin_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="+ Termin" 
     android:focusable="false" 
     android:gravity="center_horizontal|center_vertical" 
     /> 
0

您需要爲您的按鈕提供另一個背景。目前它是9個補丁,上面的一些像素標記爲不可用於打印文本(請參閱9補丁教程)。

0

設置layout_height來包裝內容會更好。另外嘗試將字體大小設置爲較小的「sp」值。