I'm using the TransitionManager.beginDelayedTransition
outlined here
to animate two views swapping positions within a RelativeLayout. I do this by simply swapping the RelativeLayout.LayoutParams
of two the two views.
My question is how do I monitor the animation that is automatically created and executed by TransitionManager
without having to create my own custom Transitions. I need to detect when the animation has ended so that I can make a change to the views that have been swapped.
Below is the method that swaps the two views. CollageCanvasAperture is an extension of View
and mApertureGroup is the RelativeLayout that holds these views.
private void shuffle(int fromApertureInd, int toApertureInd) {
final CollageCanvasAperture fromV = (CollageCanvasAperture) mApertureGroup.getChildAt(fromApertureInd);
final CollageCanvasAperture toV = (CollageCanvasAperture) mApertureGroup.getChildAt(toApertureInd);
if (null == fromV || null == toV) {
return;
}
TransitionManager.beginDelayedTransition(mApertureGroup);
RelativeLayout.LayoutParams fromLP = (RelativeLayout.LayoutParams) fromV.getLayoutParams();
RelativeLayout.LayoutParams toLP = (RelativeLayout.LayoutParams) toV.getLayoutParams();
fromV.setLayoutParams(toLP);
toV.setLayoutParams(fromLP);
}
I've done a few hours of searching on here and combing through the TransitionManager
code but can't see how to detect changes. I'd prefer to be able to detect the animation end within the CollageCanvasAperture but can't see any relevant listeners to apply.
I guess I could provide the view with the destination LayoutParams before the animation is executed and then the view can listen for size & location changes until they match...?
Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.
You can use the view animation system to perform tweened animation on Views. Tween animation calculates the animation with information such as the start point, end point, size, rotation, and other common aspects of an animation.
So it turned out it's quite straightforward to add a listener to these 'automatic' transitions.
Instead of using: TransitionManager.beginDelayedTransition(mApertureGroup);
you need to work out which automatic Transition is being using when you invoke beginDelayedTransition
and call TransitionManager.go()
instead.
My view transitions were using the ChangeBounds Transition. Once that was know all I had to do was:
ChangeBounds mySwapTransition = new ChangeBounds();
mySwapTransition.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) { }
@Override
public void onTransitionEnd(Transition transition) { }
@Override
public void onTransitionCancel(Transition transition) {}
@Override
public void onTransitionPause(Transition transition) { }
@Override
public void onTransitionResume(Transition transition) { }
});
TransitionManager.go(new Scene(mApertureGroup), mySwapTransition);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With