有没有办法以编程方式在 Android 中的图像上创建渐变?

Is there a way to programatically create a gradient on an image in Android?

在 Android。

我正在寻找一种创建背景可绘制对象的方法,这将为图像提供透明渐变。

旨在使图像的顶部比原始图像稍微不透明,并逐渐淡化为完全透明的图像。

想将其作为可绘制对象的一部分来执行此操作,以便我可以在 运行 时间内应用于 RecyclerView 中的任何项目。

如果有人有任何想法,请提供任何帮助。

示例 - 可绘制对象

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

    <item>
        <shape android:shape="rectangle">
            <gradient android:startColor="#00efefef"
                android:endColor="#ffefefef"
                android:angle="270"
                android:type="linear"/>
        </shape>
    </item>
</layer-list>