Search code examples
javaandroidandroid-imageviewshadow

Bottom transparent shadow effect for ImageView


I want to add shadow effect to my ImageView, like a transparent from bottom side. Here two images with and without shadow effect. Has any possible ways to make like this? Or is it better to take shadow svg file from the internet and put on the original imageView?


Solution

  • You can put your image in the same space with a gradient image using a RelativeLayot like this:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/your_image"/>
    
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/grad"/>
    </RelativeLayout>
    

    The "grad" image is this:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
            android:angle="270"
            android:endColor="#181818"
            android:startColor="#00000000 " />
        <corners android:radius="5dp" />
    </shape>