当我改变状态,乐透动画的可见性变为可见时,它改变了整个屏幕中按钮的大小



以下是我如何实现按钮的代码。有没有任何方法可以在不增加大小和不应用固定按钮高度的情况下进行乐透动画。

Button(modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 10.dp),
enabled = enabled,
onClick = {
onClick()
}) {
if (isLoading) {
LottieAnimation(
composition = composition,
iterations = Int.MAX_VALUE,
alignment = Alignment.Center,
dynamicProperties = dynamicProperties,
)
} else {
Text(
text = text,
)
}
}
@Composable
fun AnimatedButton() {
val selected = remember { mutableStateOf(false) }
val scale = animateFloatAsState(if (selected.value) 2f else 1f)
Column(
Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(
onClick = {  },
modifier = Modifier
.scale(scale.value)
.height(40.dp)
.width(200.dp)
.pointerInteropFilter {
when (it.action) {
MotionEvent.ACTION_DOWN -> {
selected.value = true }
MotionEvent.ACTION_UP  -> {
selected.value = false }
}
true
}
) {
Text(text = "Explore Airbnb", fontSize = 15.sp, color = Color.White)
}
}
}

最新更新