今天做一個動畫,發現設置的時間偶爾失效,概率還挺高.
類似微信聊天頁面,點擊圖片預覽,再次點擊,動畫形式回到聊天頁面的效果
final ScaleAnimation animation = new ScaleAnimation(1, 0,1, 0, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
animation.setDuration(1000);
animation.setFillAfter(false);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
mScalableImageView.clearAnimation();
mScalableImageView.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
isAnimFinished = false;
startTime = System.currentTimeMillis();
Log.e("chents","onAnimationStart=");
mViewPager.setAlpha(0f);
mBackgroundView.setAlpha(0f);
}
@Override
public void onAnimationEnd(Animation animation) {
isAnimFinished = true;
Log.e("chents","onAnimationEnd=time="+(System.currentTimeMillis()-startTime));
contentContainer.removeView(PreviewLayout.this);
}
@Override
public void onAnimationRepeat(Animation animation) {
Log.e("chents","onAnimationRepeat=");
}
});
最后解決:
//使用當前view執行動畫
startAnimation(animation);