希望我不是在这里重复一个问题;我找不到一个关于 multipleViewPropertyAnimators
的。目标是让视图在 8 秒内从 y1 动画到 y2。在第一秒淡出,然后在最后一秒淡出。
这是我在我的活动中尝试过的onCreate()
:
final View animatingView = findViewById(R.id.animateMe);
animatingView.post(new Runnable() {
@Override
public void run() {
//Translation
animatingView.setY(0);
animatingView.animate().translationY(800).setDuration(8000);
//Fading view in
animatingView.setAlpha(0f);
animatingView.animate().alpha(1f).setDuration(1000);
//Waiting 6 seconds and then fading the view back out
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
animatingView.animate().alpha(0f).setDuration(1000);
}
}, 6000);
}
});
但是,结果是从 0 到 800 的转换,以及从 0 到 1 的 alpha 都在一秒钟内完成。然后 6 秒后视图淡出。每次我调用 View.animate() 时,它看起来都会返回相同的 ViewPropertyAnimator。有没有办法让我拥有多个?我正在考虑为视图的 alpha 设置动画,将视图嵌套在相对布局中,然后为相对布局翻译设置动画。如果没有必要,我宁愿不走那条路。有谁知道更好的解决方案?