【发布时间】:2020-12-24 21:30:36
【问题描述】:
我必须在 android 中使用 lottie 动画来制作启动画面。我已经使用 match parent 作为宽度和高度。但它向我展示了屏幕边缘的一些填充,如附图所示。如果我使用 scaletype 作为 fitXY 那么它的图像在某些设备上被拉伸。如何为所有设备分辨率使用 lottie 动画文件,或者我需要询问我们的设计师更改文件吗?
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/retention_bg_welcome_color">
<com.airbnb.lottie.LottieAnimationView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_fileName="test_lottie.json"
android:adjustViewBounds="true"
app:lottie_loop="true"
app:lottie_speed="0.8" />
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
你为什么放 android:adjustViewBounds="true" ?
-
请尝试使用 lottie 视图而不是 layout_width="match_parent" 来放置 layout_width="0dp" 和 layout_height。它应该强制约束布局计算正确的大小
-
@LenaBru 之前就是这样。高度/宽度均为 0dp。我改变了这些只是为了检查。有人提到在某处添加 android:adjustViewBounds="true"。仍然在边缘填充
-
您肯定填充来自 lottie 视图而不是 lottie 视图的父级?还是父母的父母?
-
是的,我确信当我尝试放置一些虚拟视图并为其添加颜色时。我在想我们是否需要对 json 文件进行一些更改。单个 json 文件会支持所有屏幕分辨率吗?
标签: android android-layout android-animation lottie