2012-02-18 84 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”值。