【问题标题】:Android Animate view from off screen not working屏幕外的Android动画视图不起作用
【发布时间】:2012-02-12 18:15:31
【问题描述】:

我有一个完全位于屏幕外的视图,我正在尝试将其动画化到屏幕上。

当我打电话时:

view.startAnimation(tA);

什么也没发生,tA.initialize 和 tA.applyTransformation 永远不会被调用。

如果我在开始动画之前移动视图以使其任何部分都可见,则动画可以正常工作。

当视图远离父视图时,是什么阻止了视图的动画?

【问题讨论】:

    标签: android animation off-screen


    【解决方案1】:

    我通过研究同样的问题了解到,Android 动画在为它们的开始或结束提供离屏坐标时表现不佳。

    Android 论坛上有一些关于此错误已得到解决的对话,但我在 4.2 上仍然遇到问题。

    编辑:

    再想一想,我刚刚遇到了这个answer,如果您可以使用较新的 API (ObjectAnimator),它提供了一个可行的替代方案。

    View view = this;
    ObjectAnimator anim = ObjectAnimator.ofFloat(view, "y", 0, 100);
    anim.setDuration(super.animationDuration());
    anim.start();
    

    ObjectAnimator.ofFloat(view, "y", 0, 100);的属性在哪里

    ObjectAnimator.ofFloat(Object objBeingAnimated, String propertyBeingAnimated, float startValue, float endValue)
    

    【讨论】:

      【解决方案2】:

      我发现this answer 使用ValueAnimator 修改onAnimationUpdate() 中的MarginLayoutParams.topMargin(在我的情况下),从而解决了问题。我的视图一开始就设置了边距,这样视图就离开了屏幕。

      ObjectAnimator 方法很有希望,但对我不起作用,它与我使用TranslateAnimation 时遇到的屏幕外视图截断问题相同。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-19
        • 2015-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多