Android布局:按钮的垂直填充

时间:2016-01-23 10:56:36

标签: android android-layout button padding

如何让我的按钮的垂直填充足够小?

以下是一个例子:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_red_dark"
    android:padding="0dp"
    android:text="New Button"/>

这就是我得到的:

enter image description here

如您所见,仍有垂直填充 我该如何调整呢?

3 个答案:

答案 0 :(得分:1)

尝试将最小高度设置为较小的值:

android:minHeight=5dp

答案 1 :(得分:0)

在xml中添加此行,它应该删除字体的垂直填充:

android:includeFontPadding="false"

答案 2 :(得分:0)

我已经尝试过@IulianVărzaru所说的并且删除了一点填充。

顺便说一下,我认为填充来自你的android:background="@android:color/holo_red_dark"

在这里你可以看到@IulianVărzaru建议:

enter image description here

使用以下代码:

 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="180dp"
        android:background="@android:color/holo_red_dark"
        android:includeFontPadding="false"
        android:padding="0dp"
        android:text="New Button" />

但是,如果我们删除它:

enter image description here

使用以下代码:

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="180dp"
        android:includeFontPadding="false"
        android:padding="0dp"
        android:text="New Button" />

所以,我建议使用你自己的Style来为它着色,如下所示:

How to set Style for a button in Android?

或者,在样式中使用<item name="android:colorButtonNormal">#FF9800</item>

最后,在这里你可以看到好结果:

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="180dp"
        android:text="New Button" />
相关问题