Left align text inside a button in Android

I want to align text of a button to the left, I don't know how to do this, please help me how to do this in the xml file. I didn´t find the properties for this.


Solution 1:

Maybe this will help you:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left|center_vertical"
        android:text="Button" />

</LinearLayout>

Solution 2:

You probably want both

    android:gravity="left|center_vertical"

and then a little bit of space

    android:paddingLeft="5dp"

to keep the text from running up against the left edge of the button.

(Adjust the amount of padding_left as appropriate for your button art.)

Solution 3:

android:gravity="left"

Hope This will help

Solution 4:

android:gravity="left|center_vertical"

It will work but now you may need to add some padding left according to your requirement.

        android:paddingLeft="10dp"