Код: Выделить всё
@Composable
fun Screen() {
val offsetX = remember { Animatable(0f) }
val coroutineScope = rememberCoroutineScope()
Column(
Modifier.fillMaxSize().padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
modifier = Modifier
.height(40.dp)
.fillMaxWidth()
.clip(CircleShape)
.background(Color.White)
.padding(horizontal = 4.dp, vertical = 2.dp),
) {
Box(
modifier = Modifier
.size(100.dp, 40.dp)
.clip(CircleShape)
.offset(x = offsetX.value.dp)
.background(Color.Black, CircleShape)
)
Button(onClick = {
coroutineScope.launch {
offsetX.animateTo(0f, tween(400))
}
}) {
Text("reset")
}
Button(onClick = {
coroutineScope.launch {
offsetX.animateTo(80f, tween(400))
}
}) {
Text("80")
}
}
}
}
Начальное положение черного ящика
Положение черного ящика после изменения смещения
Подробнее здесь: https://stackoverflow.com/questions/790 ... d-to-a-box
Мобильная версия