我正在尝试在 Jetpack compose 中实现翻译动画,但我无法为此找到合适的来源。任何人都可以帮助我在 Jetpack compose 中实现翻译动画,我可以在其中手动设置开始和编辑位置..
最佳答案
在 jetpack compose 中转换动画的选项是 OFFSET ANIMATION 是的,我能够通过偏移动画实现这一点。我将在下面分享代码并详细注释,以便读者更容易理解它
// Courtine Scope to Run the animation in thread
val coroutineScope = rememberCoroutineScope()
val offsetX = remember { Animatable(0f) }
val offsetY = remember { Animatable(0f) }
Image(
painter = rememberDrawablePainter(
ContextCompat.getDrawable(
context,
R.drawable.image
)
),
contentDescription = "s", contentScale = ContentScale.Crop,
modifier = Modifier
.offset {
IntOffset(
offsetX.value.toInt(),
offsetY.value.toInt()
)
}
.width(300.dp)
.height(300.dp)
)
//Finally run the animation on the Click of your button or whenever you wants to start it...
coroutineScope.launch {
launch {
offsetXFirst.animateTo(
targetValue = targetValue,
animationSpec = tween(
durationMillis = 2000,
delayMillis = 0))}
launch {
offsetYFirst.animateTo(
targetValue = size.height.toFloat(),
animationSpec = tween(
durationMillis = 2000,
delayMillis = 0))}
}
https://stackoverflow.com/questions/70076735/