如何使用 LinearLayout 均匀 space 舍入 ImageButtons

How to evenly space round ImageButtons with LinearLayout

我找到了如何使用 Shape 背景创建圆形 ImageButtons 并且我找到了如何通过将宽度设置为 0dp 并将权重设置为 1 来在 LinearLayout 中均匀地 space 按钮。但是我不能将两者结合起来,所以圆形按钮不均匀 spaced

或者它们是均匀的 spaced 但不是圆的

似乎额外的 space 将转到内部按钮而不是边缘。如何让 LinearLayout 将新的空 space 分配给页边距而不是视图?

这是给我上面第二张图片的布局

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    <ImageButton
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_add_black_24dp"
            android:background="@drawable/rounded"/>

    <ImageButton
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_add_black_24dp"
            android:background="@drawable/rounded"/>

    <ImageButton
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_add_black_24dp"
            android:background="@drawable/rounded"/>
</LinearLayout>

这是背景

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
  <solid android:color="#33DDFF" />
  <corners android:radius="4dp"/>
</shape>

我找到的一个解决方案是在按钮周围和按钮之间使用空的 Spaces,并让它们占用额外的 space

    <Space
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_weight="1" >
    </Space>

我不得不移除实际按钮的重量并将宽度设置为 wrap_content

 <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_add_black_24dp"

            android:background="@drawable/rounded"
            android:contentDescription="@string/speak_button_desc"/>

试试这个:

第 1 步:设置 android:layout_width="0dp" 第 2 步:将 android:layout_weight 设置为所有按钮的总和等于 1.0

<LinearLayout android:id="@+id/linearLayout3"
android:layout_height="wrap_content" 
android:orientation="horizontal"
android:layout_width="match_parent">

<ImageButton 
  android:layout_height="wrap_content"
  android:id="@+id/clear"
  android:layout_width="0dp"
  android:layout_weight=".5" />

 <ImageButton 
 android:layout_height="wrap_content"
 android:id="@+id/submit" 
 android:layout_width="0dp"
 android:layout_weight=".5" />
 </LinearLayout>