Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FlipAnimation implements Animation.AnimationListener {
- private Animation animation1;
- private Animation animation2;
- private boolean isBackOfCardShowing = true;
- private ImageView img;
- private Context ctx;
- private FlipEnd flipped;
- Card card;
- public interface FlipEnd {
- void flipEnd(ImageView img, Card card);
- }
- FlipAnimation(Context ctx, ImageView img, Card card) {
- this.img = img;
- this.ctx = ctx;
- this.card = card;
- flipped = (FlipEnd) ctx;
- animation1 = AnimationUtils.loadAnimation(ctx, R.anim.flip_to_middle);
- animation1.setAnimationListener(this);
- animation2 = AnimationUtils.loadAnimation(ctx, R.anim.flip_from_middle);
- animation2.setAnimationListener(this);
- img.clearAnimation();
- img.setAnimation(animation1);
- img.startAnimation(animation1);
- }
- @Override
- public void onAnimationStart(Animation animation) {
- }
- @Override
- public void onAnimationEnd(Animation animation) {
- if (animation == animation1) {
- if (isBackOfCardShowing) {
- Card
- img.setImageResource(R.drawable.card_face);
- flipped.flipEnd(img,card);
- } else {
- img.setImageResource(R.drawable.card_back);
- }
- img.clearAnimation();
- img.setAnimation(animation2);
- img.startAnimation(animation2);
- } else {
- isBackOfCardShowing = !isBackOfCardShowing;
- }
- }
- @Override
- public void onAnimationRepeat(Animation animation) {
- }
- }
- <scale xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="250"
- android:fromXScale="1.0"
- android:fromYScale="1.0"
- android:pivotX="50%"
- android:pivotY="50%"
- android:toXScale="0.0"
- android:toYScale="1.0" />
- <scale
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:fromXScale="0.0" android:toXScale="1.0"
- android:pivotX="50%"
- android:fromYScale="1.0" android:toYScale="1.0"
- android:pivotY="50%"
- android:duration="250" />
Add Comment
Please, Sign In to add comment