Aseem Salim
Aseem Salim

Reputation: 211

Animation On Custom View Android

I have created a custom view shows below Custom View

I want to add an animation to the element when the user clicks on each color the color should pop down and pop up

some part of custom view code

override fun onDraw(canvas: Canvas?) {
    super.onDraw(canvas)

    // draw elements
    for(i in 0..5){
        drawElementOrCursor(canvas,cXArray[i]!!,cYArray[i]!!,elementRadius!!,colorArray[i]!!)
    }

    // draw cursor
    drawElementOrCursor(
        canvas,cXArray[0]!!,
        (elementCursorSize!!/2)+8+elementSize!!,
        elementCursorRadius!!,
        colorArray[0]!!)

}

private fun drawElementOrCursor(canvas: Canvas?,cX: Int,cY: Int,radius: Float,color: Int){
    paint.color = color
    paint.style = Paint.Style.FILL

    canvas?.drawCircle(cX.toFloat(),cY.toFloat(),radius,paint)
}

Upvotes: 0

Views: 120

Answers (1)

Ali Rezaiyan
Ali Rezaiyan

Reputation: 3309

You can do it with ObjectAnimator.

Define a specific parameter to your object and animate it with animation Interpolators that are available here

As an example, I've done here: LevelProgressBar

Upvotes: 2

Related Questions