Reputation: 77
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?
Upvotes: 3
Views: 3963
Reputation: 1
We can implement it with the help of gravity
attribute.
android:gravity="start|bottom"
Eg:
<Button
android:id="@+id/btn_submit"
android:layout_width="100dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:text="submit"
android:gravity="start|bottom"/>
Upvotes: 0
Reputation: 1283
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"/>
Upvotes: 6
Reputation: 2041
Because you set android:gravity="bottom|center_horizontal"
.
If you want its text shows in center, you should set android:gravity="center"
.
--Edit--
It was a mistake. I misunderstood.
You should set android:gravity="center|bottom"
.
Upvotes: 0
Reputation: 79
try this
<Button
android:id="@+id/CatButton"
android:layout_width="match_parent"
android:layout_height="150dp"
android:paddingBottom="20dp"
android:gravity="center_vertical|center_horizontal"
android:text="test"/>
Upvotes: 0