I went through the source code, but haven't tested the following code. From what I can tell, you want to block the call to onGlobalLayout()
for the duration of the animation. The following should achieve that:
onAnimationStart():
mPhotoView.getViewTreeObserver()
.removeOnGlobalLayoutListener((PhotoViewAttacher)mPhotoView.getIPhotoViewImplementation());
onAnimationEnd():
mPhotoView.getViewTreeObserver()
.addOnGlobalLayoutListener((PhotoViewAttacher)mPhotoView.getIPhotoViewImplementation());
Note thatremoveOnGlobalLayoutListener(OnGlobalLayoutListener)
is available for API versions >=16. Before this, you'll use removeGlobalOnLayoutListener(OnGlobalLayoutListener)
.
onAnimationStart()
and onAnimationEnd()
callbacks are available by adding a ValueAnimator.AnimatorUpdateListener
to your ValueAnimator
.
Again, I don't know if this will work - looks like it should.
Edit:
Following is independent of the code above.
Instead of animating the height
of PhotoView
, you could animate its top
& bottom
properties. In my tests, animating these properties did not reset the y
position, or change the scaleX/scaleY values:
int mOrigImageViewTop, mOrigImageViewBottom;
void crunchImageView() {
// Hold on to original values
if (mOrigImageViewTop == 0) {
mOrigImageViewTop = mImageView.getTop();
mOrigImageViewBottom = mImageView.getBottom();
}
// Top
ObjectAnimator objectAnimatorTop = ObjectAnimator.ofInt(mImageView,
"top", mOrigImageViewTop,
mOrigImageViewTop + 200 /*should be calculated dynamically*/);
// Bottom
ObjectAnimator objectAnimatorBottom = ObjectAnimator.ofInt(mImageView,
"bottom", mOrigImageViewBottom,
mOrigImageViewBottom - 200 /*should be calculated dynamically*/);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(objectAnimatorTop, objectAnimatorBottom);
animatorSet.setDuration(5000L);
animatorSet.start();
}
If you are animating the height
to make room for other views above or below the PhotoView
, animating top
/bottom
will not help. In this case, using a FrameLayout
to host the PhotoView
& other Views
, and controlling their visibility may be an option.