Android 乐天动画库Z排序问题
我目前正在玩AirBnB的Android版Lottie,我对Android 乐天动画库Z排序问题,android,android-animation,z-order,lottie-android,Android,Android Animation,Z Order,Lottie Android,我目前正在玩AirBnB的Android版Lottie,我对LottieAnimationViewZ排序有问题。无论我是否将LottieAnimationView放置在RelativeLayout的顶部,它始终显示在布局中所有其他元素的顶部,例如: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schema
LottieAnimationView
Z排序有问题。无论我是否将LottieAnimationView放置在RelativeLayout
的顶部,它始终显示在布局中所有其他元素的顶部,例如:
<RelativeLayout
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:layout_margin="@dimen/spacing_lrg"
tools:context="com.myapp.SplashActivity">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:lottie_fileName="test.json"/>
<! -- Other Elements that should appear on top of the background animation -->
</RelativeLayout>
我还尝试将lottieeanimationview
的标高设置为0,但没有成功解决该问题。有没有人知道如何解决这个问题,或者这只是库的一个限制?还有,如果这是一个限制,是什么原因造成的
编辑:
这可能已在库更新中修复,因为此问题发生在库的早期版本中(这是两年前发布的)。我会验证这是不是真的,如果是的话,我会接受一些东西来关闭这篇文章。我刚刚开始,但这个问题又重新得到重视。尝试通过代码加载乐蒂文件名。我用xml加载文件时遇到了一些问题 您可以将一个线性视图用于其他视图,并调用linearlayout.bringToFront()这很奇怪。 我建议将您的完整布局包装在框架布局中,并将Lottie作为其第一个子项,第二个子项放在小部件树的其余部分。我还没试过这个,但应该有用
或者,您是否尝试过使用立面?我建议您使用约束布局,我只是这样尝试:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.airbnb.lottie.LottieAnimationView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:id="@+id/animationLoading"
android:layout_width="200dp"
android:layout_height="200dp"
app:lottie_rawRes="@raw/thermosun"
app:lottie_loop="true"
app:lottie_autoPlay="true"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_margin="@dimen/app_default_margin_16dp"
android:text="My button"/>
</androidx.constraintlayout.widget.ConstraintLayout>
包含项目的Constraintlayout和CustomTextView的XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/closeIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:src="@drawable/ic_go_to_location"
android:layout_margin="@dimen/dimen_16dp"/>
<com.airbnb.lottie.LottieAnimationView
app:layout_constraintTop_toBottomOf="@id/closeIcon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/animationLoading"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="750:1080"
app:lottie_rawRes="@raw/thermosun"
app:lottie_loop="true"
app:lottie_autoPlay="true"/>
<com.shadows.howhotismycity.utils.CustomTextView
android:id="@+id/tvUserCounter"
android:layout_width="@dimen/dimen_30dp"
android:layout_height="wrap_content"
android:text="10"
android:textColor="@android:color/black"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/closeIcon"/>
<com.shadows.howhotismycity.utils.CustomTextView
android:id="@+id/tvSampleText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Theres some text here"
android:textColor="@android:color/black"
android:textSize="24sp"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUserCounter"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_margin="@dimen/dimen_16dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Android 10中测试的动画顶部文本视图的结果
我无法在任何布局(包括RelativeLayout)中重现您所指的问题。也许升级到最新版本可以解决这个问题。最新版本是3.4.1:
implementation'com.airbnb.android:lottie:3.4.1'
。如果您已经在使用最新版本,请共享您的完整代码,以便我们进一步调查。我已经在使用ConstraintLayout,但它不起作用。您可以发布您的constraint layout代码吗?因此,我们可以更好地帮助您我的问题是,当我在Pixel XL(Android 10.0)上测试时,您的依赖项有什么Lottie版本?我刚刚看到您的XML有一个用于文本视图的自定义小部件,您可以发布此类小部件的类吗?这可能是由于该类,因为我刚刚在约束布局中放置了两个androidx.appcompat.widget.AppCompatTextView,它们位于乐蒂动画下方,并显示在顶部。我使用的是乐蒂库的3.4.0版。我更新了要点,加入了CustomTextView。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/closeIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:src="@drawable/ic_go_to_location"
android:layout_margin="@dimen/dimen_16dp"/>
<com.airbnb.lottie.LottieAnimationView
app:layout_constraintTop_toBottomOf="@id/closeIcon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/animationLoading"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="750:1080"
app:lottie_rawRes="@raw/thermosun"
app:lottie_loop="true"
app:lottie_autoPlay="true"/>
<com.shadows.howhotismycity.utils.CustomTextView
android:id="@+id/tvUserCounter"
android:layout_width="@dimen/dimen_30dp"
android:layout_height="wrap_content"
android:text="10"
android:textColor="@android:color/black"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/closeIcon"/>
<com.shadows.howhotismycity.utils.CustomTextView
android:id="@+id/tvSampleText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Theres some text here"
android:textColor="@android:color/black"
android:textSize="24sp"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUserCounter"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_margin="@dimen/dimen_16dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
//lottie
implementation 'com.airbnb.android:lottie:3.4.0'