简体   繁体   中英

Apply two animations for two Views in Android

In my project, I have to create a game with 12 cards. At the begining of the game, all of them are face-down. If I chose one card, it will face-up. And if I continue to choose another card, if the images of both of 2 cards that are face-up is the same, the cards will disapear. If not, the cards will turn face-down again.

I am coding with Android 2.2 and I using this example about fipping animation: android-animaions-3d-flip

But I got a stuck, when I choose a card, and after that, I continue choose another one, if they are the same, both of them are disapear. This case works correctly. But if they are different, the second card is even not face-up. I think the problem may be about starting 2 animations together at the same time. Following is my code for the case when two cards are different:

 Flip3dAnimation rotation1 = new Flip3dAnimation(0, -90, centerX1, centerY1);
 rotation1.setDuration(250);
 rotation1.setFillAfter(true);
 rotation1.setInterpolator(new AccelerateInterpolator());
 rotation1.setAnimationListener(new DisplayNextView(isFirstImage[flipRid.get(0).x*3 +                 flipRid.get(0).y ], image11, image12 ));
                            image12.startAnimation(rotation1);

 Flip3dAnimation rotation2 = new Flip3dAnimation(0, -90, centerX2, centerY2); 
 rotation2.setDuration(250);
 rotation2.setFillAfter(true);
 rotation2.setInterpolator(new AccelerateInterpolator());
 rotation2.setAnimationListener(new DisplayNextView(isFirstImage[flipRid.get(1).x*3 + flipRid.get(1).y ], image21, image22 ));

 image12.startAnimation(rotation1); // First card works
 image22.startAnimation(rotation2); // Second card not work correctly

Please help me, thank you.

使用此示例并将您的3d翻转动画示例与此结合,然后解决您的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM