如何在按钮中对齐文本

时间:2015-04-26 13:47:03

标签: android button alignment

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

为了澄清,请查看图像中的红色圆圈。

enter image description here

感谢。

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

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"

/>

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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 -->
相关问题