简体   繁体   English

在Android中为两个视图应用两个动画

[英]Apply two animations for two Views in Android

In my project, I have to create a game with 12 cards. 在我的项目中,我必须创建一个有12张牌的游戏。 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 我正在使用Android 2.2进行编码,我使用这个关于fipping动画的例子: 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. 我认为问题可能在于同时启动2个动画。 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翻转动画示例与此结合,然后解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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