Android ConstraintLayout 粒子动画高程
Android ConstraintLayout particle animation elevation
我有一个大问题,我正在尝试将粒子动画置于背景中
我正在使用图书馆:https://github.com/plattysoft/Leonids
Confettis 的动画完美地显示在我的屏幕上,但它在前景中,我希望它在我的 ImageView 后面的背景中!
我尝试设置 ImageView 的高度,但动画停留在前景
我有我的 SplashScreen.xml 和 Constraintlayout :
<android.support.constraint.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:id="@+id/bg_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_splashscreen">
<ImageView
android:id="@+id/logo_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="36dp"
android:layout_marginStart="37dp"
android:layout_marginTop="8dp"
android:src="@drawable/logo"
android:elevation="4dp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_weight="0.1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline"
app:layout_constraintVertical_weight="0.1"
tools:ignore="ContentDescription" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.26371" />
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.42074" />
</android.support.constraint.ConstraintLayout>
我的五彩纸屑动画基本上是在我的 SplashScreen 的 onCreate 方法中调用的 activity。
这是在我的 Splashscreen Activity 中调用的方法:
fun particleConfettiAnimation(fromActivity: Activity?) {
if (fromActivity == null){ return }
ParticleSystem(fromActivity, 80, R.drawable.confetti, 10000)
.setSpeedModuleAndAngleRange(0f, 0.3f, 0, 0)
.setRotationSpeed(144f)
.setAcceleration(0.00035f, 100)
.emit(100, -100, 5)
}
编辑:我想我明白 ConstraintLayout 中的层次结构是:与之前创建的其他元素相比,最后创建的元素位于前景,这样可以解释为什么动画与我的 ImageView 相比处于前景
但是我该如何解决这个问题呢?
希望足够清楚,谢谢!
我找到了解决方案!
您必须像这样向 ParticleSystem 调用添加另一个参数:
ParticleSystem(fromActivity, 80, R.drawable.confetti, 10000, R.id.YOURID)
.setSpeedModuleAndAngleRange(0f, 0.3f, 0, 0)
.setRotationSpeed(144f)
.setAcceleration(0.00035f, 100)
.emit(100, -100, 5)
然后添加到 XML 文件中 ConstraintsLayout 的开头:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/YOURID">
</FrameLayout>
就是这样!
我有一个大问题,我正在尝试将粒子动画置于背景中 我正在使用图书馆:https://github.com/plattysoft/Leonids
Confettis 的动画完美地显示在我的屏幕上,但它在前景中,我希望它在我的 ImageView 后面的背景中!
我尝试设置 ImageView 的高度,但动画停留在前景
我有我的 SplashScreen.xml 和 Constraintlayout :
<android.support.constraint.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:id="@+id/bg_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_splashscreen">
<ImageView
android:id="@+id/logo_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="36dp"
android:layout_marginStart="37dp"
android:layout_marginTop="8dp"
android:src="@drawable/logo"
android:elevation="4dp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_weight="0.1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline"
app:layout_constraintVertical_weight="0.1"
tools:ignore="ContentDescription" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.26371" />
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.42074" />
</android.support.constraint.ConstraintLayout>
我的五彩纸屑动画基本上是在我的 SplashScreen 的 onCreate 方法中调用的 activity。 这是在我的 Splashscreen Activity 中调用的方法:
fun particleConfettiAnimation(fromActivity: Activity?) {
if (fromActivity == null){ return }
ParticleSystem(fromActivity, 80, R.drawable.confetti, 10000)
.setSpeedModuleAndAngleRange(0f, 0.3f, 0, 0)
.setRotationSpeed(144f)
.setAcceleration(0.00035f, 100)
.emit(100, -100, 5)
}
编辑:我想我明白 ConstraintLayout 中的层次结构是:与之前创建的其他元素相比,最后创建的元素位于前景,这样可以解释为什么动画与我的 ImageView 相比处于前景
但是我该如何解决这个问题呢? 希望足够清楚,谢谢!
我找到了解决方案!
您必须像这样向 ParticleSystem 调用添加另一个参数:
ParticleSystem(fromActivity, 80, R.drawable.confetti, 10000, R.id.YOURID)
.setSpeedModuleAndAngleRange(0f, 0.3f, 0, 0)
.setRotationSpeed(144f)
.setAcceleration(0.00035f, 100)
.emit(100, -100, 5)
然后添加到 XML 文件中 ConstraintsLayout 的开头:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/YOURID">
</FrameLayout>
就是这样!