Android 翻牌动画 实现

来源:互联网 发布:淘宝试用申请成功后 编辑:程序博客网 时间:2024/06/06 19:09

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

/** * 翻牌动画 */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"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <scale        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"/></set>

动画二:front_scale.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <scale        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"/></set>



原创粉丝点击