Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lottie animation padding

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!

like image 629
Madalin Avatar asked Jul 27 '18 07:07

Madalin


2 Answers

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

      <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/animationView"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:scaleType="fitXY"
        app:lottie_autoPlay="true"
        android:padding="10dp"
        app:lottie_loop="true"
        app:lottie_rawRes="@raw/your_json_file_here"/></RelativeLayout>

** Try this code. it's working **

like image 158
Shiva Kanumala Avatar answered Sep 30 '22 21:09

Shiva Kanumala


Just treat it like any other view and use the setPadding programmatically.

LottieAnimationView btnHeart;

btnHeart.setPadding(-150, -150, -150, -150);
like image 39
Stha Sandes Avatar answered Sep 30 '22 21:09

Stha Sandes