Oliver Dixon
Oliver Dixon

Reputation: 7405

Draw gradient transparent circle around Bitmap

I've got a bitmap from file and I need to be able to draw it with a gradient around it (gradually going more transparent). How would I go about this? I've looked around and can't find much.

Point in the right direct would help thanks.

-Edit-

I'd like to do this programatically, say with bitmap class and canvas.

I've drawn a picture to show my problem. (Still stuck with this): https://i.sstatic.net/9aFMu.jpg

Upvotes: 0

Views: 604

Answers (1)

Frank Sposaro
Frank Sposaro

Reputation: 8531

You can do this in xml.

<?xml version="1.0" encoding="UTF-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >

            <!-- end colour at top, start colour at bottom -->
            <!-- Your colors can include hex alpha values --> 
            <!-- #ff000000 is fully transparent black -->
            <!-- #00000000 is non transparent black -->
            <!-- There are more options in that link to control the gradient more -->
            <gradient
                android:type="radial"
                android:endColor="@color/endColor" 
                android:startColor="@color/startColor"/>

        </shape>

    </item>

    <!-- top, bottom left and right adds padding -->
    <item android:bottom="3px">
        <Bitmap src="@drawable/yourBitmap />
    </item>
</layer-list>

Here is a great link with more information about xml drawables. http://idunnolol.com/android/drawables.html

Upvotes: 1

Related Questions