【发布时间】:2011-05-18 07:56:04
【问题描述】:
我的 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>
【问题讨论】:
-
文字已经居中了……你还想改什么?
-
它没有垂直居中,顶部空间比底部空间大。
-
您是否尝试过完全删除重力标签或仅使用垂直标签?
-
我猜你可以尝试设置填充
-
@Rosalie:我设置了
android:paddingBottom="3sp",这似乎使它排列正确。不过,我仍然很想知道为什么这是整个应用程序中唯一无法自动对齐文本的按钮。