【发布时间】:2021-04-05 03:26:00
【问题描述】:
允许用户使用滑块沿 Y 轴更改屏幕上的按钮位置。发生这种情况时,我想为我的 Button 设置动画。例如,View 位于 (0,0),用户突然将其位置设置在 (0, 420)。
按钮应首先淡出(在 400 毫秒内从 alpha 1.0 到 alpha 0.0),同时位于当前位置 (0,0)。
然后,Button 位置应更改为 (0,420),并且应在位于更改的位置 (0, 420) 时淡入(在 400 毫秒内从 alpha 0.0 到 alpha 1.0)。
由于按钮位置可以很快改变,所以我得到的是一个华丽的动画效果,这是我不想要的。 这是我的代码:
/* Alpha from 1 to 0 */
ObjectAnimator animation = ObjectAnimator.ofFloat(myButton, "alpha", 1, 0);
animation.setDuration(400);
animation.setRepeatCount(1);
animation.setInterpolator(new LinearInterpolator());
animation.start();
/* Alpha from 0 back to 1 */
animation = ObjectAnimator.ofFloat(myButton, "alpha", 0, 1);
animation.setDuration(400);
animation.setRepeatCount(1);
animation.setInterpolator(new LinearInterpolator());
animation.start();
【问题讨论】:
标签: android animation objectanimator