我正在尝试将图像从右到左移动一个“V”(从上到下)。这是一张描述我所追求的图像:
我尝试使用ObjectAnimator
,AnimatorSet
但我没有得到我想要得到的东西。很难理解为什么我会得到别的东西。
这是我当前的代码:
/**
* translateLeft = -160dp
* translateDown = 25dp
* translateUp = -25dp
*/
private void vShapedAnimation () {
AnimatorSet upDownSet = new AnimatorSet();
AnimatorSet downUpSet = new AnimatorSet();
AnimatorSet finalSet = new AnimatorSet();
ObjectAnimator rightToLeft = ObjectAnimator.ofFloat(this.imageView, View.TRANSLATION_X, this.getResources().getDimensionPixelOffset(R.dimen.translateLeft) / 2);
ObjectAnimator upDown = ObjectAnimator.ofFloat(this.imageView, View.TRANSLATION_Y, this.getResources().getDimensionPixelOffset(R.dimen.translateDown));
ObjectAnimator downUp = ObjectAnimator.ofFloat(this.imageView, View.TRANSLATION_Y, this.getResources().getDimensionPixelOffset(R.dimen.translateUp));
upDownSet.playTogether(
rightToLeft,
upDown
);
downUpSet.playTogether(
rightToLeft,
downUp
);
finalSet.playSequentially(
upDownSet,
downUpSet
);
finalSet.setDuration(300);
finalSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
animation.removeListener(this);
animation.setDuration(0);
animation.setInterpolator(new ReverseInterpolator());
animation.start();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
finalSet.start();
}
来自ReverseInterpolator
这里AnimatorListener
:
我打算同时旋转一下图像。如果“V”可以向内弯曲一点,那将是完美的。但是,如果一开始有人可以帮我做基本的动画,那将不胜感激。