如何防止 LinearLayout Android 菜单中按钮之间的空格?

how to prevent spaces between buttons in LinearLayout Android Menu?

我在 RelativeLayout 中有 LinearLayout,所以我想将按钮放在父布局的顶部。 我添加了 4 个相对权重相等的按钮(“1”),因此它们的大小都相等。 现在它是这样显示的,但我想要一个没有空格的外观。

这些按钮没有任何 space。这是因为背景可绘制对象在左侧和右侧包含透明填充。 将按钮的背景更改为某种颜色(例如 android:background="#f01123"),您将看到按钮之间没有 space。

如果按钮的背景设置失败,就会出现这个问题,要么设置透明,要么设置一些颜色作为背景。请不要将其留空,否则将分配默认按钮 属性。我已经为你制作了样本。请试试这个..

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:orientation="horizontal">

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/white"
            />

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/white"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:layout_weight="1"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:layout_weight="1"/>
    </LinearLayout>

</RelativeLayout>