【问题标题】:How to increase the lottie "LottieAnimationView" dimensions?如何增加lottie“LottieAnimationView”尺寸?
【发布时间】:2017-04-02 19:15:58
【问题描述】:

我正在使用Lottie 制作动画。问题是lottie 视图尺寸太小。有没有办法在lottie中自定义尺寸?

【问题讨论】:

  • 您可以手动设置视图的大小,动画将在不损失质量的情况下进行缩放,或者使用指南设置约束,这是在同一视图上处理未知或多个动画大小时最有用的方法.

标签: android android-animation lottie


【解决方案1】:

我尝试了@Sijansd 的答案,但是LottieComposition.Factory 现在已被弃用。所以我想尝试缩放视图。这就是我为使它工作所做的。 (经过测试且 100% 正常工作)

android:scaleType="fitXY"

所以最终的代码是这样的

<com.airbnb.lottie.LottieAnimationView
            android:id="@+id/lottie_view"
            android:layout_width="200dp"
            android:scaleType="fitXY"
            android:layout_height="30dp"
            android:layout_gravity="center"
            app:lottie_autoPlay="true"
            app:lottie_fileName="animation.json"
            app:lottie_loop="true" />

【讨论】:

  • fitXY 不会在某些设备上拉伸图像?
【解决方案2】:

尝试使用 animation.setScale(0.4f);

0.1f 是最小的。

【讨论】:

    【解决方案3】:

    使用“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);
    
    }));
    

    【讨论】:

      【解决方案4】:

      我知道这是一个旧线程,但我遇到了同样的问题,即 Lottie 动画显得太小。简单的答案是在表单中定义“Scale”:AnimationView。 Scale="1" 是原始大小。使用“2”或“3”等可以扩大规模。相反,“.5”或任何缩小它的值。希望对某人有所帮助。

      <ContentPage.Content>
      
          <forms:AnimationView Scale="5"
              x:Name="animationView"
              Grid.Row="1"
              Animation="lottieAnimation.json"
              Loop="true"
              AutoPlay="true"         
              VerticalOptions="FillAndExpand"
              HorizontalOptions="FillAndExpand" />
      
      </ContentPage.Content>
      

      【讨论】:

        猜你喜欢
        • 2020-11-24
        • 2023-03-24
        • 1970-01-01
        • 2015-01-27
        • 2018-05-21
        • 1970-01-01
        • 1970-01-01
        • 2015-07-01
        • 1970-01-01
        相关资源
        最近更新 更多