期望:
我希望像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>
但它不起作用。有解决方案吗
您的活动或片段的布局
<?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>
drawable 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>
根据需求变化颜色