Android:如何使按钮标题居中?

发布于 2025-01-06 11:38:54 字数 460 浏览 3 评论 0原文

我有一个像这样的按钮......

 <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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

‖放下 2025-01-13 11:38:54

使用 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"
        />

use wrap_content for your layout height and use style="?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:

    <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"
        />
西瑶 2025-01-13 11:38:54

您需要为按钮提供另一个背景。目前它是 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).

要走干脆点 2025-01-13 11:38:54

通过设置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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文