Лотти Анимация Библиотека Z Проблема заказа
В настоящее время я играю с лотерейной библиотекой AirBnB для Android, и у меня возникают проблемы с 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>
Я также попытался установить LottieAnimationView
Возвышение до 0, но безуспешно при устранении проблемы. У кого-нибудь есть идеи, как это исправить, или это просто ограничение библиотеки? Кроме того, если это ограничение, что является причиной?
1 ответ
Я не могу воспроизвести проблему, о которой вы говорите, в любом макете, включая RelativeLayout. Возможно, обновление до последней версии решит проблему. Последняя версия - 3.4.1:implementation 'com.airbnb.android:lottie:3.4.1'
. Если вы уже использовали последнюю версию, поделитесь своим полным кодом, чтобы мы могли продолжить расследование.
Это странно. Я бы посоветовал обернуть ваш полный макет внутри макета фрейма и поставить 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>
Сообщите мне, если это сработает!:)
----- РЕДАКТИРОВАТЬ ---- Класс CustomTextView
class CustomTextView : AppCompatTextView {
constructor(context: Context) : super(context) {
init(context)
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init(context, attrs)
}
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
context,
attrs,
defStyle
) {
init(context, attrs)
}
private fun init(context: Context, attrs: AttributeSet? = null) {
if (!isInEditMode) {
@Suppress("Recycle")
context.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView).use {
setUpCharacterSpacing(
it.getFloat(R.styleable.CustomTextView_characterSpacing, 0.0f)
)
setUpLineSpacing(
it.getDimension(R.styleable.CustomTextView_lineSpacing, 0f)
)
}
paintFlags = paintFlags or Paint.SUBPIXEL_TEXT_FLAG
}
}
private fun setUpLineSpacing(lineSpacing: Float) {
if (lineSpacing != 0f) {
setLineSpacing(lineSpacing - textSize, 1f)
}
}
}
XML с Constraintlayout и 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'
Результат текстового просмотра поверх анимации, протестированной в Android 10
Попробуйте загрузить файл лотереи по имени. У меня были некоторые проблемы при загрузке файла по XML
Вы можете использовать один Linear для просмотра других и вызывать linearlayout.bringToFront()