gpt4 book ai didi

android - 如何在Jetpack Compose中实现翻译动画?

转载 作者:行者123 更新时间:2023-12-05 09:30:00 27 4
gpt4 key购买 nike

我正在尝试在 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))}
}

关于android - 如何在Jetpack Compose中实现翻译动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70076735/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com