我在我的Android应用中遇到了按钮文本对齐的问题。我在XML中这样定义了一个按钮:
<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"/>
结果是这样的:
结果如下:
我希望文字在垂直和水平方向上都居中,就像应用程序中的所有其他按钮一样,但是对于这个按钮,它稍微往下偏移了一点。我似乎无法弄清楚为什么会这样,所以需要帮助。
编辑: 下面是按钮背景的XML:
<?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>
android:paddingBottom="3sp"
,这样似乎可以正确对齐。不过,我还是很好奇为什么这个按钮是整个应用中唯一一个无法自动对齐文本的按钮。 - jvergeldedios