I'm having trouble with button text alignment in my Android app. I have a button defined in XML like this:
<Button
android:id="@+id/reportanissuebutton"
android:layout_width="272sp"
android:layout_height="32sp"
android:text="@string/button_report_issue"
android:textColor="#fff"
android:textSize="18sp"
android:gravity="center_vertical|center_horizontal"
android:background="@xml/report_issue_button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40sp"/>
The result is this:
button.jpg
I was expecting the text to be centered both vertically and horizontally as it does with all of the other buttons in my application, but for some reason with this one it is offset slightly down. I can't seem to figure out why its doing this, so any help would be appreciated.
Edit: Here is the XML for the background of the button:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="6dp" />
<stroke android:color="#c2c2c2" android:width="2dp" />
<gradient
android:angle="90"
android:startColor="#000"
android:endColor="#919191"/>
</shape>
That worked for me:
android:gravity="fill_vertical"
Hope it helps!
Try this:
android:includeFontPadding="false"
It helped me with a similar problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With