带有动画的Android矩阵后缩放

时间:2020-05-10 14:20:31

标签: android matrix android-imageview

一个想法不了解足够的矩阵理论,无法在图像视图内为矩阵构建动画。 例如,我有一些要在postScale方法中设置为矩阵的值。

我使用此代码

fun animateScale(scale_factor:Float,matrix: Matrix)
{
    matrix.postScale(scale_factor,scale_factor)
    image_view.imageMatrix = matrix
}

此代码可以按预期缩放到图像视图。但是我不能用动画计算postScale。我尝试使用ValueAnimator.ofFloat(0f, 1f)ValueAnimator.ifInt(1, 100)使用其他方法,但结果很奇怪。

已更新 我按评论要求添加了动画效果的尝试。

val animator = ValueAnimator.ofFloat(0f, 1f)
    animator.addUpdateListener(
        { animation ->

            val current_anim_value = animation.animatedValue as Float

            val factor_to_anim = scale_factor - ( scale_factor * current_anim_value)
            matrix.postScale(factor_to_anim, factor_to_anim)
            image_view.imageMatrix = matrix
        })

    animator.duration = 3000
    animator.start()

0 个答案:

没有答案