I am trying to achieve frame animation in jetpack Compose.
I know in the android view system, it can be achieved by using AnimationDrawable.
But how to properly use animation drawable class in jetpack Compose?
CodePudding user response:
Finally i found a solution.I achieved frame animation using animation drawable in jetpack compose by creating animation drawable programmatically and assign it to Image as Drawable.Finally is ued animation drawable refrence to control the animation.I am posting the Sample Code Below...
val animationDrawable = AnimationDrawable()
//add your images in animationDrawable by giving information of duration etc like you gave in xml file..
Image(
painter = rememberDrawablePainter(animationBlast),
contentDescription = null,
Modifier
.offset {
IntOffset(
offsetX.toInt() - (if (size == 250) 300 else 0),
offsetY.toInt() - (if (size == 250) 300 else 0)
)
}
.size(size.dp), contentScale = ContentScale.Crop
)
animationDrawable?.start()