Android: 3D vertical flip animation-FlipAnimation

Source: Internet
Author: User

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 ();}}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.