首页 > 解决方案 > 圆角透明渐变安卓故障

问题描述

我有一个包含 ImageViews 的项目的 RecyclerView,我想在其上显示渐变阴影。显示一些文字。我尝试过带有圆角的可绘制形状的视图,我尝试过使用 ShapeableImageView,我尝试过使用卡片视图。它们都会导致角落变色的相同奇怪图形故障。

这是我的可绘制视图

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="@dimen/card_corner_radius" />
    <gradient
        android:endColor="@color/card_shadow_bottom"
        android:startColor="@color/card_shadow_top"
        android:angle="270"
        android:type="linear" />
</shape>

这是我的项目布局


        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/iv_image"
                imageUrl="@{obj.imageUrl}"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/content_image_description"
                android:scaleType="centerCrop" />

            <View
                android:id="@+id/v_card_shadow"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@drawable/card_shadow"
                app:layout_constraintBottom_toBottomOf="@+id/iv_image"
                app:layout_constraintEnd_toEndOf="@+id/iv_image"
                app:layout_constraintStart_toStartOf="@+id/iv_image"
                app:layout_constraintTop_toTopOf="@+id/iv_image" />
        </androidx.constraintlayout.widget.ConstraintLayout>

这是结果: 这就是结果

是什么原因造成的?我该如何解决?

标签: androidandroid-drawable

解决方案


推荐阅读