Android(安卓)翻牌动画 实现
16lz
2021-12-04
原理:由两个动画组合实现;监听第一个动画结束,开始第二个动画,具体代码如下
/** * 翻牌动画 */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:TextSwitcher、imageSwitcher
- Android弹性动画三种实现方式
- activity页面切换效果
- Android(安卓)Bundle类
- Android8.1 系统修改默认的wifi直连名字
- Android的Listview用法总结和Adapter的使用
- android代码分析,及Terminal使用
- Android(安卓)Studio -- Error retrieving parent for item: No
- android中四个典型动画设置