Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ripple effect in custom view

I am currently creating an Android view in which, when the use tap it, I will display a sort of ripple around the coordinate of the tap.

But I'm not sure on how to do it. My first idea was to invalidate the cache and just make the circle bigger each time but it doesn't seem appropriate nor efficient to do this like that.

If anyone faced the same problem before and would love the share some tips on how to do it it would be much appreciated.

like image 468
Matthieu Meunier Avatar asked Oct 24 '25 02:10

Matthieu Meunier


1 Answers

I finally found out a solution. Not a perfect one but it works for now.

Here is the code I did. Basically when I need it I change a boolean to true so my onDrawfunction knows that it have to execute the drawFingerPrintfunction.

The drawFingerPrint function, in the other end, just draw a circle that's bigger and bigger between each iteration until it reaches the diameter needed

private fun drawFingerPrint(canvas: Canvas) {
        canvas.drawCircle(pointerX, pointerY, radius, paint)

        if(radius<= 100F){
            radius+=10F
            invalidate()
        }
        else{
            radius = 0F
            drawAroundFinger = false
            invalidate()
        }
    }

I hope someone else will find this useful sometimes!

Matthieu

like image 67
Matthieu Meunier Avatar answered Oct 26 '25 16:10

Matthieu Meunier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!