圆形矩形图像选择器形状在棒棒糖中无法正确显示

问题描述 投票:0回答:1

我正在尝试将选择器放在图像上,这是矩形,它在棒棒糖上工作正常但不在棒棒糖及其较低版本中。

我使用带有两个图像的cardview,一个带有imageselector和一个实际图像。

任何人都可以指导我为什么它不能正常工作!

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">

        <item>
            <shape android:tint="@color/transparent">
                <solid android:color="@android:color/transparent" />
                <stroke
                    android:width="3dp"
                    android:color="@color/black" />

                <corners
                    android:bottomLeftRadius="20dp"
                    android:bottomRightRadius="20dp"
                    android:topLeftRadius="20dp"
                    android:topRightRadius="20dp" />
            </shape>
        </item>
        <item
            android:bottom="2dp"
            android:left="2dp"
            android:right="2dp"
            android:top="2dp">
            <shape android:tint="@color/transparent">
                <solid android:color="@android:color/transparent" />
                <stroke
                    android:width="2dp"
                    android:color="@color/white" />

                <corners
                    android:bottomLeftRadius="20dp"
                    android:bottomRightRadius="20dp"
                    android:topLeftRadius="20dp"
                    android:topRightRadius="20dp" />
            </shape>
        </item>
    </layer-list>





<android.support.v7.widget.CardView
                android:id="@+id/image_selector_item_card_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:cardCornerRadius="20dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                android:layout_margin="2dp"
                android:clipToPadding="true">
                <ImageView
                    android:id="@+id/image_selector_item_image_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"/>
                <ImageView
                    android:id="@+id/border_selected"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/image_selector_selected_border"/>
            </android.support.v7.widget.CardView>

预计:enter image description here

在棒棒糖:enter image description here

android xml android-layout android-5.0-lollipop shapes
1个回答
1
投票

您可以将此简化为以下测试的代码

dummy.xml里面的drawable

<item>
    <shape android:shape="rectangle">
        <solid android:color="@color/white"/>
        <stroke android:color="@color/black" android:width="3dp"/>
        <corners android:radius="20dp"/>
    </shape>
</item>

<android.support.v7.widget.CardView
    android:id="@+id/image_selector_item_card_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="true"
    app:cardCornerRadius="20dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/dummy">

        <ImageView
            android:id="@+id/image_selector_item_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="6dp"
            android:scaleType="centerCrop" />
    </LinearLayout>
</android.support.v7.widget.CardView>

让我知道它是否有效

© www.soinside.com 2019 - 2024. All rights reserved.