在 Compose 中,您可以透過幾種方式為向量製作動畫。你可以使用下列任一方法:
AnimatedVectorDrawable
檔案格式ImageVector
,例如這篇 Medium 文章- 第三方解決方案,例如 Lottie
動畫向量可繪項目 (實驗功能)

如要使用 AnimatedVectorDrawable
資源,請使用 animatedVectorResource
載入可繪項目檔案,然後傳遞到 boolean
,以便讓可繪項目切換開始和結束狀態,並執行動畫。
@Composable fun AnimatedVectorDrawable() { val image = AnimatedImageVector.animatedVectorResource(R.drawable.ic_hourglass_animated) var atEnd by remember { mutableStateOf(false) } Image( painter = rememberAnimatedVectorPainter(image, atEnd), contentDescription = "Timer", modifier = Modifier.clickable { atEnd = !atEnd }, contentScale = ContentScale.Crop ) }
有關可繪項目檔案格式的詳細資訊請參閱「以動畫方式呈現可繪項目圖形」。
為您推薦
- 注意:系統會在 JavaScript 關閉時顯示連結文字
- 載入圖片 {:#loading-images}