Lottie 动画填充

Lottie animation padding

我有一个问题要问那些有使用 lottie json 文件经验的人。我使用 lottie 的经验不多,所以我想我可能缺少一些明显的知识。当我将动画渲染到视图中时,动画对象会像那样放置在视图的中心

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

有没有一种方法可以修改 json 文件,使动画对象适合整个视图:

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

我试过像这样在 xml 中设置视图:

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

但是没用
我也尝试设置更大的比例:

app:lottie_scale="2" 

但我没有成功。 感谢您的宝贵时间!

使用"LottieDrawable"和"LottieComposition"您可以轻松设置比例。波纹管代码 100% 适合我。

<?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>

和Java部分

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

    }));

就像对待任何其他视图一样对待它并以编程方式使用 setPadding。

LottieAnimationView btnHeart;

btnHeart.setPadding(-150, -150, -150, -150);
<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>

** 试试这段代码。它的工作 **