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" />
它有固定的大小,如果我在手机上测试该应用程序,文本不会在按钮中居中,因此文本的底部会被剪切。看这里:图片
你有什么建议吗?
I have a Button like this....
<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" />
It has a fixed size and if I test the App on my phone the text is not getting centered in the button, so the bottom of the text gets cut. Look here :Picture
Do u have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
wrap_content
作为布局高度并使用style="?android:attr/buttonStyleSmall"
。您将得到一个较小的按钮,其大小与您想要的大小相似:
您的代码应如下所示:
use
wrap_content
for your layout height and usestyle="?android:attr/buttonStyleSmall"
.you will get a smaller button, which has a size similar to the size you want:
your code should look like this:
您需要为按钮提供另一个背景。目前它是 9 补丁,顶部的一些像素标记为不可用于打印文本(仔细查看 9 补丁教程)。
You need to provide another background for your button. Currently it is 9-patch, for which some pixels on top marked as unavailable for print-in text (look close at 9-patch tutorials).
通过设置layout_height来包装内容会得到更好的服务。还可以尝试将字体大小设置为较小的“sp”值。
You would be better served by setting the layout_height to wrap content. Also try setting the font Size to a lesser "sp" value.