I have seen examples of 'card flip animations' where the entire layout of an activity is changed using the animation, much like the developer docs here.
Is there a way I can have a similar kind of animation but only on one view?
Specifically, I have a ViewFlipper
which contains two CardView
s. When I flip the views, I would like there to be a flipping animation.
Currently I have sliding animations, but here is what I have so far:
private void showPrevious() {
// If there aren't any other children, stop.
if (mViewFlipper.getDisplayedChild() == 0) {
return;
}
// Next screen comes in from left.
mViewFlipper.setInAnimation(this, R.anim.slide_in_from_left);
// Current screen goes out from right.
mViewFlipper.setOutAnimation(this, R.anim.slide_out_to_right);
// Display next screen.
mViewFlipper.showNext();
}
private void showNext() {
// If there is a child (to the left), stop.
if (mViewFlipper.getDisplayedChild() == 1) {
return;
}
// Next screen comes in from right.
mViewFlipper.setInAnimation(this, R.anim.slide_in_from_right);
// Current screen goes out from left.
mViewFlipper.setOutAnimation(this, R.anim.slide_out_to_left);
// Display previous screen.
mViewFlipper.showPrevious();
}
Could the slide animations I have be replaced with a flip animation (where it appears as though the CardView is rotated in 3D)?
I've made an Android library that contains a collection of useful widgets - it's called UsefulViews.
One of these widgets is the FlippableView
.
You can have a look at the Javadoc to see how it works.