如何结合平移和缩放动画



我正在尝试结合比例和平移动画,但我在这些动画之后的图像是碎片化的

动画

//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

<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"/>
您只需在

视图所在的 java 类(活动/片段/适配器(中即可完成此操作。等(喜欢

 view.animate().rotationBy(360).translationX(50).scaleXBy(1).setDuration(1000);

根据需要编辑值

您应该考虑使用动画集。 下面是一个示例

溶液:

翻译

        val animatorLogoLoginTransaction = ObjectAnimator.ofFloat(
            logoLogin,
            View.TRANSLATION_Y,
            -logoStateTopValue
        )
        animatorLogoLoginTransaction.startDelay = 500

规模

    val scalaAnimation = ScaleAnimation(1f,0.4f,1f,0.4f,
          Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f)

    val animSet = AnimationSet(true)
        animSet.fillAfter = true
        animSet.duration = 1000
        animSet.interpolator = BounceInterpolator()
        animSet.addAnimation(animatorLogoLoginTransaction)
        animSet.addAnimation(scalaAnimation)
        your_view.startAnimation(animSet)

最新更新