Mad*_*lin 9 animation android json padding lottie
我有一个问题要问那些有使用 lottie json 文件经验的人。我使用 lottie 的经验并不多,所以我想我可能遗漏了一些明显的知识。当我将动画渲染到视图中时,动画对象像这样放置在视图的中心
_____________________________________________
| |
| [animated object] |
|_____________________________________________|
Run Code Online (Sandbox Code Playgroud)
有没有办法可以修改 json 文件以使动画对象适合整个视图:
_____________________________________________
| |
| [a n i m a t e d o b j e c t s ]|
|_____________________________________________|
Run Code Online (Sandbox Code Playgroud)
我试过在 xml 中设置视图,如下所示:
android:scaleType="centerCrop"
android:adjustViewBounds="true"
Run Code Online (Sandbox Code Playgroud)
但它不起作用
我也试图设置更大的规模:
app:lottie_scale="2"
Run Code Online (Sandbox Code Playgroud)
但我没有成功。感谢您的时间!
小智 5
<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>
Run Code Online (Sandbox Code Playgroud)
** 试试这个代码。它正在工作**
小智 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>
Run Code Online (Sandbox Code Playgroud)
和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);
}));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6822 次 |
| 最近记录: |