Android 翻牌动画 实现

原理:由两个动画组合实现;监听第一个动画结束,开始第二个动画,具体代码如下

/**
 * 翻牌动画
 */
public void cardTurnover() {
    scan_barcode_iv.setImageResource(R.drawable.but_tex);
    if (back_scale_animation == null) {
        back_scale_animation = AnimationUtils.loadAnimation(getContext(), R.anim.back_scale);
    }
    back_scale_animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            scan_barcode_iv.setImageResource(R.drawable.but_icon);
            if (front_scale_animation == null) {
                front_scale_animation = AnimationUtils.loadAnimation(getContext(), R.anim.front_scale);
            }
            LinearInterpolator lir = new LinearInterpolator();
            front_scale_animation.setInterpolator(lir);
            scan_barcode_iv.startAnimation(front_scale_animation);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    LinearInterpolator lir = new LinearInterpolator();
    back_scale_animation.setInterpolator(lir);
    scan_barcode_iv.startAnimation(back_scale_animation);
}
动画一:back_scale.xml
xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android">
            android:fromXScale="1.0"
        android:toXScale="0.0"
        android:fromYScale="1.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="200"/>

动画二:front_scale.xml
xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android">
            android:fromXScale="0.0"
        android:toXScale="1.0"
        android:fromYScale="1.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="200"/>



你可能感兴趣的:(Android,翻牌,动画,android,动画)