How to start text view from the right in a button android

时间:2016-08-31 12:29:54

标签: android android-layout android-view android-button

I have a button with an icon and a text inside of it. When I set the button's width to match_parent, the text inside the button gets placed in the middle. I want the text to start from the right side of the button and not in the middle. How can I achieve this?

<Button
    android:layout_margin="10dp"
    android:id="@+id/select_flight_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/button_material_light"
    android:drawableLeft="@drawable/icon_select_flight"
    android:maxHeight="@dimen/global_button_height"
    android:minHeight="@dimen/global_button_height"
    android:text="@string/choose_flight"
    android:textColor="@drawable/custom_text_color_for_buttons"
    android:textSize="@dimen/button_text_size"
    android:textStyle="bold"
    android:layout_below="@+id/view"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

screenshot example

1 个答案:

答案 0 :(得分:0)

图片和要求不匹配 它是正确的,中心是垂直的,从右边开始

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_action_accept"
    android:gravity="right|center_vertical"
    android:padding="15dp"
    android:text="Chooose Flight "
    android:textStyle="bold" />