[英]How to combine translation and scale animation?
I'm trying to combine scale and translate animation but my image after these animations is fragmented 我正在尝试结合缩放和平移动画,但是这些动画之后的图像碎片化了
Animations 动画制作
//TODO: **Translate**
val animatorLogoLoginTransaction = ObjectAnimator.ofFloat(
logoLogin,
View.TRANSLATION_Y,
-logoStateTopValue
)
animatorLogoLoginTransaction.startDelay = 500
animatorLogoLoginTransaction.duration = 1000
animatorLogoLoginTransaction.start()
//TODO: **Scale**
val scalaAnimation = val scalaAnimation = ScaleAnimation(1f,0.4f,1f,0.4f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f)
scalaAnimation.fillAfter = true
scalaAnimation.duration = 1000
logoLogin.startAnimation(scalaAnimation)
XML of my image view 我的图像视图的XML
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/logoLogin"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:scaleType="fitStart"
android:layout_marginStart="16dp"
android:src="@drawable/vree_logo_large"
app:layout_constraintTop_toTopOf="@id/limitGuideLogo"
app:layout_constraintLeft_toLeftOf="parent"/>
You can do it simply in the java class where the view comes (activity/fragment/adapter..etc) like 您可以在视图所在的java类(activity / fragment / adapter..etc)中简单地做到这一点,例如
view.animate().rotationBy(360).translationX(50).scaleXBy(1).setDuration(1000);
Edit values as required 根据需要编辑值
You should consider using the animation set. 您应该考虑使用动画集。 here is an example 这是一个例子
Solution: 解:
Translate 翻译
val animatorLogoLoginTransaction = ObjectAnimator.ofFloat(
logoLogin,
View.TRANSLATION_Y,
-logoStateTopValue
)
animatorLogoLoginTransaction.startDelay = 500
Scale 规模
val scalaAnimation = ScaleAnimation(1f,0.4f,1f,0.4f,
Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f)
Combine 结合
val animSet = AnimationSet(true)
animSet.fillAfter = true
animSet.duration = 1000
animSet.interpolator = BounceInterpolator()
animSet.addAnimation(animatorLogoLoginTransaction)
animSet.addAnimation(scalaAnimation)
your_view.startAnimation(animSet)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.