【问题标题】:How can I align text in a button如何对齐按钮中的文本
【发布时间】:2015-07-04 21:14:12
【问题描述】:

我想对齐左侧按钮中的文本,但根本不对齐。

为了清楚起见,请看图片中的红色圆圈。

谢谢。

(图片中的第一个是我的结果,第二个是我想要的)

xml 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/activity_libretto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
>
<Button
android:id="@+id/button"
    style="?android:attr/borderlessButtonStyle"
    android:textAllCaps="false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:text="Buongiorno!"
    android:textSize="19dp"
    android:textStyle="bold"
    android:layout_marginTop="15dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="20dp"
    android:gravity="left|center_vertical"
    android:background="@drawable/bg_button"
    android:drawableRight="@drawable/arrow"

/>

【问题讨论】:

  • 所以要将文本左对齐?

标签: android button alignment


【解决方案1】:

在按钮的xml中使用android:gravity="left|center_vertical",也可以添加android:paddingLeft="YOUR PADDING IN dp"

【讨论】:

    【解决方案2】:

    将android:gravity="left|center_vertical" 添加到您的按钮。

    <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button"
            android:gravity="left|center_vertical"/>  <!-- this line -->
    

    【讨论】:

      猜你喜欢
      • 2015-07-06
      • 2021-12-26
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      • 2017-03-17
      • 2020-10-05
      • 1970-01-01
      相关资源
      最近更新 更多