Horizo​​ntal LinearLayout space 项目之间没有左右填充

Horizontal LinearLayout space between items without padding left and right

我需要在 LinearLayout 中的项目之间 space 两侧没有填充。

这张图片会解释它:

这是XML:

    <LinearLayout
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_marginBottom="32dp"
        android:orientation="horizontal">


        <ImageView
            android:id="@+id/rateOneStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_star"
            app:tint="@color/ratingStarInactive" />

        <ImageView
            android:id="@+id/rateTwoStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_star"
            app:tint="@color/ratingStarInactive" />

        <ImageView
            android:id="@+id/rateThreeStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_star"
            app:tint="@color/ratingStarInactive" />

        <ImageView
            android:id="@+id/rateFourStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_star"
            app:tint="@color/ratingStarInactive" />

        <ImageView
            android:id="@+id/rateFiveStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_star"
            app:tint="@color/ratingStarInactive" />
    </LinearLayout>

我现在正在使用这个解决方案:

https://github.com/google/flexbox-layout

代替线性布局:

    <com.google.android.flexbox.FlexboxLayout
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_marginBottom="32dp"
        app:justifyContent="space_between">

编辑:更好的解决方案

在边缘视图上设置 layoutWeight 会移除它们周围的填充。

<LinearLayout
        android:id="@+id/requested"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_marginBottom="32dp"
        android:orientation="horizontal"
        app:layout_constraintTop_toBottomOf="@id/original">


        <ImageView
            android:id="@+id/rateOneStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="0"
            app:srcCompat="@drawable/ic_round_credit_card_24"
            app:tint="@color/colorLightBlack" />

        <ImageView
            android:id="@+id/rateTwoStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_round_credit_card_24"
            app:tint="@color/colorLightBlack" />

        <ImageView
            android:id="@+id/rateThreeStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="0"
            app:srcCompat="@drawable/ic_round_credit_card_24"
            app:tint="@color/colorLightBlack" />

        <ImageView
            android:id="@+id/rateFourStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/ic_round_credit_card_24"
            app:tint="@color/colorLightBlack" />

        <ImageView
            android:id="@+id/rateFiveStar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_weight="0"
            app:srcCompat="@drawable/ic_round_credit_card_24"
            app:tint="@color/colorLightBlack" />
    </LinearLayout>