Alpha-gradient on Android [duplicate]
Asked Answered
S

3

19

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

Image for example

Siblee answered 15/1, 2013 at 19:59 Comment(2)
also take a look at here: https://mcmap.net/q/258960/-text-with-gradient-in-android should also work for an ImageView.Been
@Been Yep. This is correct answer. Thank you!Siblee
U
1

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>
Unravel answered 7/8, 2020 at 8:12 Comment(0)
C
4
<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
                android:startColor="#00FFFFFF"
                android:endColor="#FFFFFFFF"
                android:type="linear" />
    </shape>

perfect transperancy. Make sure that the View below gradient is actually below and not just touching Gradient shape View.

If you have main RelativeLayout, ListView and View(Background:Gradient )

make sure that Gradient View is on top, of the ListView, and not a side. If Your gradient is aside it will be transparent by RelativeLayout Background Color and not by ListView .

i hope you understand what i want to say.

Conal answered 23/10, 2014 at 14:17 Comment(0)
S
2

For transparency :

android:startColor="@null"

Or you can use a 8-digit hex color like that :

android:startColor="#FF000000"

The first two FF are for the alpha of the color, 00 is fully transparent and FF opaque

Specious answered 19/6, 2019 at 9:45 Comment(0)
U
1

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>
Unravel answered 7/8, 2020 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.