Search code examples
androidimageviewgradientandroid-imageviewalpha-transparency

Alpha-gradient on Android


I need to create an alpha-gradient on the edge of the ImageView. Preferably using only XML.

Image for example


Solution

  • Need to code a custom ImageView if you want colorless transparency.

    If your background is a static color, here's my preferred workaround:

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