Android: 3D vertical flip animation-FlipAnimation
Requirement
Perform an animation similar to a card turning on the ImageViewSolution
Combination of various Animator
Step 1:
Animation code file 1, card_flip_left_out.xml
Step 2 Animation
Animation file 2: card_flip_left_out
Below is the java code. At the end of the first animation, change the image.
Package com. example. android. animationsdemo; import android. animation. animator; import android. animation. animatorInflater; import android. animation. animatorListenerAdapter; import android. animation. animatorSet; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. imageView;/*** @ date 2:28:33 pm on October 11 * @ author Zheng Haibo * @ Description: Image flip animation */public class ImageFlipActivity extends Activity {private ImageView imageView; private int clickCount = 0; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_image_flip); imageView = (ImageView) findViewById (R. id. iv_show); imageView. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {playFlipAnimation2 () ;}});} private void playFlipAnimation2 () {clickCount ++; animatorSet animatorSetOut = (AnimatorSet) AnimatorInflater. loadAnimator (this, R. animator. card_flip_left_out); final AnimatorSet animatorSetIn = (AnimatorSet) AnimatorInflater. loadAnimator (this, R. animator. card_flip_left_in); animatorSetOut. setTarget (imageView); animatorSetIn. setTarget (imageView); animatorSetOut. addListener (new AnimatorListenerAdapter () {@ Override public void onAnimationEnd (Animator animation) {// after turning 90 degrees, change the image if (clickCount % 2 = 0) {imageView. setImageResource (R. drawable. image1);} else {imageView. setImageResource (R. drawable. image2);} animatorSetIn. start () ;}}); animatorSetIn. addListener (new AnimatorListenerAdapter () {@ Override public void onAnimationEnd (Animator animation) {// TODO}); animatorSetOut. start ();}}