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

标签 android android-layout android-button

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

 <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

你有什么建议吗?

最佳答案

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

关于Android:如何使按钮标题居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9342062/

相关文章:

android - 如何在android中顺利删除?

android - 如果所有 subview 都不能水平放置,如何将布局方向更改为垂直

java - 操作栏布局看起来不正确

android - 如何使按钮闪烁?

安卓 : Create a button with border bottom

java - In-App Billing V3 - 购买 3 个月后过期的对象 - Android

android - 不可见的 Ndef 消息

android - 我应该在 Android Jetpack Compose 中使用 ConstraintLayout 以获得更好的性能吗?

android - 无法找到以下设计的布局

android - 如何在 Cordova 项目中使用 PhoneGap Developer App