If you want to shake your view then slowly stop, we can reduce the translation value after each round.
This is a helper function
fun animateHorizontalShake(
view: View,
offset: Float,
repeatCount: Int = 3,
dampingRatio: Float? = null,
duration: Long = 1000L,
interpolator: Interpolator = AccelerateDecelerateInterpolator()
) {
val defaultDampingRatio = dampingRatio ?: (1f / (repeatCount + 1))
val animValues = mutableListOf<Float>()
repeat(repeatCount) { index ->
animValues.add(0f)
animValues.add(-offset * (1 - defaultDampingRatio * index))
animValues.add(0f)
animValues.add(offset * (1 - defaultDampingRatio * index))
}
animValues.add(0f)
val anim: ValueAnimator = ValueAnimator.ofFloat(*animValues.toFloatArray())
anim.addUpdateListener {
view.translationX = it.animatedValue as Float
}
anim.interpolator = interpolator
anim.duration = duration
anim.start()
}
Example slow
animateHorizontalShake(imageView, 200f, repeatCount = 4, duration = 10000L)

Example fast
animateHorizontalShake(imageView, 50f, repeatCount = 4, duration = 1000L)

Or even if you dont want the shake show down
animateHorizontalShake(imageView, 50f, dampingRatio = 0f, interpolator = LinearInterpolator())
With above code, also remember to use dp value for offset
for support multiple devices instead of hardcode