LinearLayout中按钮之间的间距相等

Pét*_*son 1 android button android-layout android-linearlayout

我在LinearLayout中垂直排列了四个按钮。

纽扣

我希望按钮之间的空间,最顶部按钮与线性布局的顶部之间的空间以及最底部按钮与布局的底部之间的空间相同。

在附图中,空格被描绘为红色路径。我希望所有空间都具有相同的大小。

我将如何实现自己的目标?

<LinearLayout
            p1:orientation="vertical"
            p1:layout_width="wrap_content"
            p1:layout_height="wrap_content"
            p1:id="@+id/mainButtonLayout">
            <Button
                p1:text="xxx"
                p1:layout_width="match_parent"
                p1:layout_height="wrap_content"
                p1:id="@+id/saButton"
                p1:textColor="#FFFFFF"
                p1:background="@drawable/roundedBlue"
                p1:minHeight="33dp"
                p1:minWidth="175dp"
                p1:layout_marginBottom="20dp" />
            <Button
                p1:text="xxxx"
                p1:layout_width="match_parent"
                p1:layout_height="wrap_content"
                p1:id="@+id/rButton"
                p1:textColor="#FFFFFF"
                p1:background="@drawable/roundedBlue"
                p1:minHeight="33dp"
                p1:minWidth="175dp"
                p1:layout_marginBottom="20dp" />
            <Button
                p1:text="xxxxx"
                p1:layout_width="match_parent"
                p1:layout_height="wrap_content"
                p1:id="@+id/sButton"
                p1:textColor="#FFFFFF"
                p1:background="@drawable/roundedBlue"
                p1:minHeight="33dp"
                p1:minWidth="175dp"
                p1:layout_marginBottom="20dp" />
            <Button
                p1:text="xxxxx"
                p1:layout_width="match_parent"
                p1:layout_height="wrap_content"
                p1:id="@+id/pButton"
                p1:textColor="#FFFFFF"
                p1:background="@drawable/roundedBlue"
                p1:minHeight="33dp"
                p1:minWidth="175dp" />
        </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Har*_*mar 5

在LinearLayout中使用weightsum

<LinearLayout
...
android:weightSum="4.0">`
Run Code Online (Sandbox Code Playgroud)

在每个按钮中,根据需要放置layout_height = 0dp,layout_weight = 1,上下边距,但每个按钮都相同。

<Button....
...
android:layout_height="0dp"
android:layout_weight="1.0"
android:layout_marginBottom="40dp"
android:layout_marginTop="40dp"
/>
Run Code Online (Sandbox Code Playgroud)

有关更多信息:请阅读此文档