Search code examples
androidandroid-layoutandroid-button

Align the text of a button to the bottom


I am facing a problem.
I want to align the text of a button to the bottom with a padding of 20dp. However, the text sticks at the bottom of my button.

<Button
    android:id="@+id/CatButton"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:paddingBottom="20dp"
    android:background="@drawable/rounded_1_selected"
    android:gravity="bottom|center_horizontal"
    android:text="test"/>

Can anyone please help me?


Solution

  • If you change layout_gravity = "bottom", your button align bottom; but if you change gravity = "bottom", your button's text align bottom. You should do that:

    <Button
                android:id="@+id/catButton"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:layout_gravity="center" 
                android:text="test"
                android:gravity="center|bottom"/>