Hot questions for Using Lottie in json

Question:

I have a question for the ones of you who have experience using lottie json files. I am not so experienced using lottie so I thought maybe I am missing some obvious knowledge. When I render my animation into a view, the animation object are placed in the center of the view like that

 _____________________________________________
|                                             |
|        [animated object]                    |
|_____________________________________________|

Is there a way I can modify the json file to make the animated objects fit the whole view like that:

     _____________________________________________
    |                                             |
    | [a n i m a t e d         o b j e c t s     ]|
    |_____________________________________________|

I have tried setting the view in the xml like that:

android:scaleType="centerCrop"
android:adjustViewBounds="true"

but it didn't work I also tried to set a greater scale:

app:lottie_scale="2" 

but I had no success. Thank you for your time!


Answer:

Using "LottieDrawable" and "LottieComposition" you can set scale easily. Bellow code is 100% working for me.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/animation_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:lottie_loop="true"
    app:lottie_autoPlay="true"/>

</LinearLayout>

and Java part

LottieAnimationView animationView = findViewById(R.id.animation_view);

LottieDrawable drawable = new LottieDrawable();

    LottieComposition.Factory.fromAssetFileName(this, "anim_1.json",(composition -> {
        drawable.setComposition(composition);
        drawable.playAnimation();
        drawable.setScale(3);
        animationView.setImageDrawable(drawable);

    }));

Question:

I have made an animation by adobe after effects and exported JSON file with images and it works

as i have put photos from the assets folder

THE PROBLEM i want to change one of the images which are in the JSON file

"assets": [
 {
  "id": "image_0",
  "w": 960,
  "h": 540,
  "u": "images/",
  "p": "img_0.png"
}

this is the piece of the JSON file that has the id i don't know how to change it or to change the name or to set images programmatically

in other words I want to change a specific image that I choose from my java code and put another image for example change the shirt image


Answer:

found the Answer after some research simply use this function

lottieAnimationView.updateBitmap("the id of the image which is found in the json file",thebitmap);