יש כמה דרכים ליצור אנימציה של וקטור ב-Compose. אפשר להשתמש בכל אחד מהבאים:
- פורמט הקובץ
AnimatedVectorDrawable
ImageVector
באמצעות ממשקי API של אנימציות ב-Compose, כמו שמתואר במאמר הזה ב-Medium- פתרון של צד שלישי כמו Lottie
פריטים גרפיים וקטורים שניתן לשרטוט עם אנימציה (ניסיוני)

כדי להשתמש במשאב AnimatedVectorDrawable
, צריך לטעון את קובץ ה-drawable באמצעות animatedVectorResource
ולהעביר boolean
כדי לעבור בין מצב ההתחלה למצב הסיום של ה-drawable, ולבצע את האנימציה.
@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 ) }
מידע נוסף על הפורמט של קובץ ה-drawable זמין במאמר אנימציה של גרפיקה ניתנת לציור.
מומלץ עבורך
- הערה: טקסט הקישור מוצג כש-JavaScript מושבת
- Loading images {:#loading-images}