Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android button fine text alignment

I'm trying to create standard button in android with a background and some text in front but some fairly specific alignment. I want the text to be centered vertically and on the left with 20dp of padding. The alignment works but the padding doesn't. I know I could probably get the desired effect by putting a few spaces in the text but that seems like a hack and next I want to do a similar thing but with the text at the top so I would prefer a more elegant solution. Here's what I have:

<Button
        android:layout_width="312dp"
        android:layout_height="95dp"
        android:id="@+id/gv_music_button"
        android:text="Music"
        android:textSize="30sp"
        android:paddingLeft="20dp"
        android:gravity="left|center_vertical"
    />
like image 843
skorulis Avatar asked Sep 03 '10 01:09

skorulis


People also ask

Does text align work on buttons?

The text-align property applies to the horizontal placement of the text within the button, not the alignment of the button itself.

How do you right align text on android?

To right align text in TextView in Kotlin Android, set android:textAlignment attribute with the value “viewEnd” in layout file, or programmatically set the textAlignment property of the TextView object with View.

How do you left align text on android?

To left align the text in this Textview through layout file, set the android:textAlignment attribute for the TextView to “viewStart”, as shown in the following activity_main. xml layout file.


1 Answers

My mistake, padding was working correctly. Just didn't appear to be.

like image 85
skorulis Avatar answered Nov 14 '22 04:11

skorulis