Compose में ऐनिमेशन वाली वेक्टर इमेज

Compose में, वेक्टर में ऐनिमेशन जोड़ने के लिए कुछ अलग-अलग तरीकों का इस्तेमाल किया जा सकता है. इनमें से कोई भी तरीका इस्तेमाल किया जा सकता है:

  • AnimatedVectorDrawable फ़ाइल फ़ॉर्मैट
  • ImageVector Compose के ऐनिमेशन एपीआई के साथ, जैसे कि इस मीडियम लेख में बताया गया है
  • तीसरे पक्ष का कोई समाधान, जैसे कि Lottie

ऐनिमेटेड वेक्टर ड्रॉएबल (एक्सपेरिमेंटल)

घड़ी के आकार का ऐनिमेशन, जिसमें रेत गिरती हुई दिख रही है और घड़ी घूम रही है
पहला डायग्राम. Compose में ऐनिमेटेड वेक्टर ड्रॉएबल

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
    )
}

अपने ड्रॉएबल की फ़ाइल के फ़ॉर्मैट के बारे में ज़्यादा जानने के लिए, ड्रॉएबल ग्राफ़िक में ऐनिमेशन जोड़ना लेख पढ़ें.