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

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

ऐनिमेटेड वेक्टर ड्रॉएबल (यह सुविधा, प्रयोग के तौर पर उपलब्ध है)

घड़ी के आकार का ऐसा ऐनिमेशन जिसमें रेत गिरती हुई दिख रही है और घड़ी घूम रही है
पहला डायग्राम. 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
    )
}

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