【问题标题】:Strange behaviour ScaleAnimation setFillAfter(true) / false奇怪的行为 ScaleAnimation setFillAfter(true) / false
【发布时间】:2012-10-26 15:43:56
【问题描述】:

我们正在使用 TouchImageView 并希望实现 onDoubleTap 缩放... 到目前为止一切顺利。

问题是:

如果我们应用缩放动画并设置setFillAfter(false),在AnimationListener.onAnimationEnd中,我们将正确的矩阵应用到imageview 和 一切都按预期工作(滚动、其他缩放手势等)。 -> 但是 - 你会在屏幕上看到一个小的闪烁(这是可以理解的 - 因为动画会跳回到开头,然后会应用矩阵更改)

另一方面,如果setFillEnabled(true),动画看起来很棒,没有闪烁,但不知何故视图完全混乱,起初一切看起来都很棒,但是最大和最小缩放级别完全搞砸了 - 你不能再缩小到初始缩放,而且移动图片不起作用正如预期的那样 - 边界是错误的?类似的东西)

那么我们的问题 ;)?
- 带有 setFillAfter(true) 的 ScaleAnimation 实际上有什么作用?
- 它会改变(完整)图像视图的大小吗?
- 出了什么问题:/?

一如既往地非常感谢您的帮助 :=) 干杯,

//顺便说一句:在所有 android 版本 中都会发生这种情况,在 4.1 上,所描述的问题不会出现,并且一切都按预期工作。

---------------
更新:
所以当前的代码是这样的,可以工作,(缩放不再有问题)但是在设置矩阵和清除动画之间有一个小的“闪烁”(尽管)代码显示,它应该应用矩阵 -before - 动画被清理了,所以我希望无缝过渡...
感谢您的回复!

            Log.v("TouchImageView", "Zoom in");
            ScaleAnimation zoomIn = new ScaleAnimation(saveScale, SCALE_DOUBLE_TAP, saveScale, SCALE_DOUBLE_TAP, width / 2, height / 2);
            zoomIn.setDuration(200);
            zoomIn.setFillAfter(true);
            zoomIn.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                    isAnimating = true;
                    saveScale = SCALE_DOUBLE_TAP;
                    right = width * saveScale - width - (2 * redundantXSpace * saveScale);
                    bottom = height * saveScale - height - (2 * redundantYSpace * saveScale);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    isAnimating = false;
                    matrix.postScale(SCALE_DOUBLE_TAP, SCALE_DOUBLE_TAP, width / 2, height / 2);
                    matrix.getValues(matrixValues);
                    setImageMatrix(matrix);
                    clearAnimation();
                }
            });


            startAnimation(zoomIn);

【问题讨论】:

    标签: android animation matrix touch imageview


    【解决方案1】:

    setFillAfter(true) 会假装它实际上是缩放的,我建议将它与矩阵缩放结合使用。在动画结束时应用矩阵并在应用了动画的View 上调用clearAnimation()。这应该可以解决闪烁问题。

    【讨论】:

    • 很好的提示,非常感谢您的解释 :) 周一早上我开始工作 :=) 我会让你知道它有效.. 但听起来好像会“秘密答案;D”
    • 嘿,刚刚应用了您的更改,它以某种方式“工作......”但是现在,由于 clearAnimation 清除了动画,我在屏幕上看到了一个小的“闪烁”,你看到动画得到了清除,然后应用矩阵,我更新了上面的帖子,也许你知道如何避免这种情况:)
    猜你喜欢
    • 2016-03-07
    • 2013-10-21
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 1970-01-01
    • 2020-08-17
    • 2019-03-08
    相关资源
    最近更新 更多