0

XML File

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <app.rive.runtime.kotlin.RiveAnimationView
        android:id="@+id/animationView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginBottom="10dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:riveResource="@raw/loading_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>

Kotlin file

package com.example.basicriveapp

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.startup.AppInitializer
import app.rive.runtime.kotlin.RiveAnimationView
import app.rive.runtime.kotlin.RiveInitializer

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        AppInitializer.getInstance(this)
            .initializeComponent(RiveInitializer::class.java);

        var animationView = findViewById<RiveAnimationView>(R.id.animationView);
        animationView.pause();
    }
}

Since I am trying to pause the Animation, it is not working and Can you please explain how to use play() and stop() methods with RiveAnimationView

Jayesh Hadke
  • 11
  • 1
  • 2

1 Answers1

0

You need to specify the animation name you want to play/pause inside the parentheses:

animationView.pause("animation name");
animationView.play("animation name");

You can get the animation name from the rive editor under the panel called "Animations"

Jamal N
  • 351
  • 1
  • 6