[英]Android: animating view in onClick()
我有想要在用戶點擊它時為其設置動畫的ImageView。
所以我最終得到了這個簡單的解決方案:
public void onClick(View v) {
imageView.animate()
.rotationX(360).rotationY(360)
.setDuration(1000)
.setInterpolator(new LinearInterpolator());
}
它只是完美的, 但只有第一次 (第一次點擊播放動畫,在該動畫完全不起作用后)。
我該如何解決這個問題?
您需要在每個動畫之前或之后重置旋轉。 例如:
imageView.animate()
.rotationX(360).rotationY(360)
.setDuration(1000)
.setInterpolator(new LinearInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
imageView.setRotationX(0);
imageView.setRotationY(0);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.