我在玩Jetpack Compose基础教程时想在
附有视频以澄清我的意思。检查每行左侧的星形图标
。
Row
中添加一个居中的Icon
,但无法进行动画。能否实现平滑的动画效果,在内容展开时图标始终垂直居中对齐?目前它只是"跳动"。类似于animateContentSize
modifier
的一些东西。尝试过这个, 但无法使其工作,因为在那个示例中它从起始位置对齐到结束位置,而不是居中。附有视频以澄清我的意思。检查每行左侧的星形图标
![enter image description here](https://istack.dev59.com/Jncm3.gif)
@Composable
fun CardContent(name: String) {
var expanded by remember { mutableStateOf(false) }
Row(
modifier = Modifier
.padding(12.dp)
.animateContentSize(
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = Icons.Filled.Star, "",
)
Column(
modifier = Modifier
.weight(1f)
.padding(12.dp)
) {
Text(text = "Hello, ")
Text(
text = name,
style = MaterialTheme.typography.h4.copy(
fontWeight = FontWeight.ExtraBold
)
)
if (expanded) {
Text(
text = ("Composem ipsum color sit lazy, " +
"padding theme elit, sed do bouncy. ").repeat(4),
)
}
}
IconButton(onClick = { expanded = !expanded }) {
Icon(
imageVector = if (expanded) Icons.Filled.ExpandLess else Icons.Filled.ExpandMore,
contentDescription = if (expanded) {
stringResource(R.string.show_less)
} else {
stringResource(R.string.show_more)
}
)
}
}
}