1

Expectation:

Screenshot of image with black fade to top

I want to give effect like a black shadow at the top of the ImageView, only on top. I've tried create a shape for background of the ImageView like this:

<?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>

But it doesn't work. Any solutions?

Atif AbbAsi
  • 5,633
  • 7
  • 26
  • 47
yoppie97
  • 177
  • 4
  • 18

1 Answers1

0

Layout for your activity or fragment

<?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>

based on requirement change color

sasikumar
  • 12,540
  • 3
  • 28
  • 48