【问题标题】:Animate ImageButton back to initial position动画 ImageButton 回到初始位置
【发布时间】:2018-04-17 22:40:51
【问题描述】:

我是 android 动画的新手。 所以,我有一个 ImageButton,我正在制作这样的动画:

ObjectAnimator Y = ObjectAnimator.ofFloat(img, "y", 300f);
Y.setDuration(1000);

所以,我的 ImageButton 通过这个动画向下移动。我如何将它向上移动(到它的初始位置)我尝试将-y 作为 y 的反转,但它的语法错误。那么什么是正确的语法呢?

【问题讨论】:

    标签: android android-animation animator animatorset


    【解决方案1】:

    ObjectAnimator Y = ObjectAnimator.ofFloat(img, "y", -300f);

    没有名为-y 的属性。 y 表示视图的左上角位置 (x,y)。

    【讨论】:

    • -300f 将其移出屏幕边界。 -0.5f 工作正常!感谢您的帮助。
    • 还有一件事。我在屏幕的最右侧有一个 ImageButton。我想将它动画到屏幕中心。我试过了:ObjectAnimator Y = ObjectAnimator.ofFloat(img, "x", -300f);。但是 img 移动到屏幕的最左侧位置。尝试更改为-0.1f。没有成功。
    猜你喜欢
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 2015-12-24
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    相关资源
    最近更新 更多