Blink CardView does not start [Object Animator, Android]

149 views Asked by At

today I'm trying to make blink effect in my CardView... Works if I put backgroundColor but does not if I use strokeColor. I've followed this tutorial to make it real but is not working really... How can I change to make this effect correctly?

 private fun createBlinkEffect() {

    val animator = ObjectAnimator.ofInt(mCardView,
        "strokeColor",
        ContextCompat.getColor(this, COLOR.WHITE),
        ContextCompat.getColor(this, COLOR.RED))

    animator.duration = 400
    animator.setEvaluator(ArgbEvaluator())
    animator.repeatMode = ValueAnimator.REVERSE
    animator.repeatCount = ValueAnimator.INFINITE
    animator.start()
}

this is my layout_item

<androidx.cardview.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mCardView"
    android:layout_width="120dp"
    android:layout_height="152dp"
    android:layout_marginEnd="24dp"
    android:layout_marginBottom="4dp"
    app:strokeWidth="2dp"
    app:strokeColor="@android:color/transparent"
    app:cardCornerRadius="12dp">

Thanks for your time

1

There are 1 answers

0
Antonio Labra On

That's it!

private fun createBlinkEffect() {
        ObjectAnimator.ofArgb(mCardView,
            "strokeColor",
            ContextCompat.getColor(this, Color.RED)).apply {
            duration = 500
            repeatCount = Animation.INFINITE
            addUpdateListener { mCardView.invalidate() }
            start()
        }
    }

Ps. Remember use MaterialCardView instead CardView and set a default strokeWidth and strokeColor