自定义视图布局线在 API 16 中覆盖其他元素

Custom view layout line overstriking other elements in API 16

问题:

我需要的:

在 API 23 上一切正常,但在 API 16 上我在模拟器中遇到了这个问题 运行。 Android Studio 还在设备屏幕上显示正确的布局。

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cardview="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    cardview:cardCornerRadius="2dp"
    cardview:cardElevation="4dp"
    style="@style/AppTheme"
    cardview:cardUseCompatPadding="true">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">

            <TextView
                android:id="@+id/tv_compra_header_titulo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="4dp"
                android:text="ETAPA"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:visibility="gone" />

            <ImageView
                android:id="@+id/iv_compra_one"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/ic_looks_one_black_24dp"

                android:backgroundTint="@android:color/tab_indicator_text" />

            <View
                android:id="@+id/view_compra_header_one"
                android:layout_width="wrap_content"
                android:layout_height="3dip"
                android:layout_alignParentEnd="false"
                android:layout_alignParentStart="false"
                android:layout_centerVertical="true"
                android:background="@color/secondaryText"
                android:layout_toEndOf="@+id/iv_compra_one"
                android:layout_toStartOf="@+id/iv_compra_two" />

            <ImageView
                android:id="@+id/iv_compra_two"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center"
                android:background="@drawable/ic_looks_two_black_24dp"
                android:backgroundTint="@android:color/tab_indicator_text" />

            <View
                android:id="@+id/view_compra_header_two"
                android:layout_width="wrap_content"
                android:layout_height="3dip"
                android:layout_alignParentEnd="false"
                android:layout_alignParentStart="false"
                android:layout_centerVertical="true"
                android:background="@color/secondaryText"
                android:layout_toStartOf="@+id/iv_compra_three"
                android:layout_toEndOf="@+id/iv_compra_two" />


            <ImageView
                android:id="@+id/iv_compra_three"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_alignParentEnd="false"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:background="@drawable/ic_looks_3_black_24dp"
                android:backgroundTint="@android:color/tab_indicator_text" />
        </RelativeLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

请记住,Android API 级别 16 不支持 startend 属性,因为它们是在 API 级别 17 中引入的。因此那些被忽略了。

只需添加等效的 leftright 属性即可使布局适用于 API 16 级及以下级别。