Để dùng tài nguyên AnimatedVectorDrawable, hãy tải tệp có thể vẽ lên bằng animatedVectorResource và truyền vào boolean để chuyển đổi giữa trạng thái bắt đầu và kết thúc của đối tượng có thể vẽ, thực hiện ảnh động.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-27 UTC."],[],[],null,["Animating vectors in Compose is possible in a few different ways. You can use any of the following:\n\n- `AnimatedVectorDrawable` file format\n- `ImageVector` with Compose animation APIs, like in [this Medium article](https://medium.com/androiddevelopers/making-jellyfish-move-in-compose-animating-imagevectors-and-applying-agsl-rendereffects-3666596a8888)\n- A third-party solution like [Lottie](https://airbnb.design/lottie/)\n\nAnimated vector drawables (experimental) **Figure 1.** Animated vector drawable in Compose\n\nTo use an [`AnimatedVectorDrawable`](/reference/android/graphics/drawable/AnimatedVectorDrawable) resource, load up the drawable file using `animatedVectorResource` and pass in a `boolean` to switch between the start and end state of your drawable, performing the animation.\n\n\n```kotlin\n@Composable\nfun AnimatedVectorDrawable() {\n val image = AnimatedImageVector.animatedVectorResource(R.drawable.ic_hourglass_animated)\n var atEnd by remember { mutableStateOf(false) }\n Image(\n painter = rememberAnimatedVectorPainter(image, atEnd),\n contentDescription = \"Timer\",\n modifier = Modifier.clickable {\n atEnd = !atEnd\n },\n contentScale = ContentScale.Crop\n )\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/animations/AnimationSnippets.kt#L915-L927\n```\n\n\u003cbr /\u003e\n\nFor more information about the format of your drawable file, see [Animate drawable graphics](/guide/topics/graphics/drawable-animation).\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Loading images {:#loading-images}](/develop/ui/compose/graphics/images/loading)"]]