【问题标题】:How to combine translation and scale animation?如何结合平移和缩放动画?
【发布时间】:2019-12-03 10:47:01
【问题描述】:

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

动画

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

【问题讨论】:

  • 查看我的更新答案。希望它会帮助你。如果它适合您,请考虑接受。

标签: android xml animation kotlin scale


【解决方案1】:

您应该考虑使用动画集。 here 就是一个例子

解决办法:

翻译

        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)

【讨论】:

    【解决方案2】:

    你可以简单地在视图所在的java类(activity/fragment/adapter..etc)中做到这一点

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

    根据需要编辑值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 2015-03-30
      • 2013-12-17
      • 2011-03-31
      • 2012-07-08
      • 1970-01-01
      • 2018-05-13
      相关资源
      最近更新 更多