I have created a 3D flip of a view using this android tutorial However, I have done it programmatically and I would like to do it all in xml, if possible. I am not talking about simply shrinking a view to the middle and then back out, but an actual 3D flip.
Is this possible via xml?
One of the better solution to flip the image with out use of the resource animation , is as follow:-
Here is the answer, though it only works with 3.0 and above.
1) Create a new resources folder called "animator".
2) Create a new .xml file which I will call "flipping". Use the following xml code:
No, the objectAnimator tags do not start with an uppercase "O".
3) Start the animation with the following code:
I got all this from here.
Since the answers to this question are fairly dated, here is a more modern solution relying on ValueAnimators. This solution implements a true, visually appealing 3D-flip, because it not just flips the view, but also scales it while it is flipping (this is how Apple does it).
First we set up the ValueAnimator:
And the corresponding update listener:
That's it!
After this setup you can flip the views by calling
and reverse the flip by calling
If you want to check if the view is flipped, implement and call this function:
You can also check if the view is currently flipping by implementing this method:
You can combine the above functions to implement a nice function to toggle the flip, depending on if it is flipped or not:
That's it! Simple and easy. Enjoy!
The simplest way to do it is using ViewPropertyAnimator
Using the fluent interface you can build more complex and exciting animation. E.g. you can enable hardware acceleration just call withLayer() method(API 16). More here
If you want to figure out how to create 3d flick animation, please follow here and here
I implemended my own solution only for a research. It includes: cancelation, accelleration, support API >= 15 and is based on Property Animation. The entire animation includes 4 parts, 2 for each side. Every objectAnimator has a listener that defines current animation index and represents an image in the onAnimationStart and current play time value in the onAnimationCancel. It looks like
For start set call
If AnimatorSet was canceled we can calculate delta and run the reverse animation relying on the current index animation and the current play time value.
full example here
I have created a simple program for creating flip of view like :
In Activity you have to create this method, for adding flip_rotation in view.
for this, you have to copy main class used to provide flip_rotation.
The tutorial or the link by om252345 don't produce believable 3D flips. A simple rotation on the y-axis isn't what's done in iOS. The zoom effect is also needed to create that nice flip feel. For that, take a look at this example. There is also a video here.