如何让ImageView生效

How to give effect to ImageView

预期:

我想在 ImageView 的顶部产生类似黑色阴影的效果,仅在顶部。我试过为 ImageView 的背景创建一个形状,如下所示:

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

    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/black_1_50"/>
            <!--shadow Color-->
        </shape>
    </item>

    <item
            android:left="0dp"
            android:right="0dp"
            android:top="20dp"
            android:bottom="0dp">
        <shape android:shape="oval">
            <solid android:color="@color/white_1_60"/>
        </shape>
    </item>
</layer-list>

但是没用。有什么解决办法吗?

您的activity或片段

的布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher_background"
        android:adjustViewBounds="true" />

<View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/shadoweffects" />
 </FrameLayout>

可绘制shadoweffects.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">

<gradient
        android:angle="90"
        android:endColor="#aa000000"    
        android:startColor="#00ffffff"
        android:centerColor="#00ffffff" />
</shape>

根据要求更改颜色