简体   繁体   English

如何在按钮中对齐文本

[英]How can I align text in a button

I want align the text in my button on the left, but not at all. 我想在左侧的按钮中对齐文本,但根本不需要。

for clarifying, look at the red circle in the image. 为了澄清起见,请查看图像中的红色圆圈。

在此处输入图片说明

Thanks. 谢谢。

(the first in the image is my result, the secondo what i'll want) (图像中的第一个是我的结果,第二个是我想要的)

xml code : 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"

/>

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

Add android:gravity="left|center_vertical" to your button. 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 -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM