animator之用scale 动画作出3d翻转动画的效果

实现原理:两张图片交替在x轴或y轴做缩放动画

private ScaleAnimation sato1=new ScaleAnimation(1, 0, 1, 1, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
private ScaleAnimation sato2=new ScaleAnimation(0, 1, 1, 1, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
private void initAnim() {
    showImage1();
    sato1.setDuration(500);
    sato2.setDuration(500);
    ivMine.startAnimation(sato1);
    sato1.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (ivMine.getVisibility()==View.VISIBLE) {
                ivMine.setAnimation(null);
                ivMine2.startAnimation(sato2);
                showImage2();
             }else {
                ivMine2.setAnimation(null);
                ivMine.startAnimation(sato2);
                showImage1();

            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

}
private void showImage1(){
    ivMine.setVisibility(View.VISIBLE);//图片1可见
    ivMine2.setVisibility(View.INVISIBLE);//图片2不可见
}

private void showImage2(){
    ivMine.setVisibility(View.INVISIBLE);//图片1不可见
    ivMine2.setVisibility(View.VISIBLE);//图片2可见
}

xml布局:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/iv_mine"
        android:layout_width="@dimen/dp_25"
        android:layout_height="@dimen/dp_25"
        android:src="@mipmap/zuan_01" />

    <ImageView
        android:id="@+id/iv_mine_2"
        android:layout_width="@dimen/dp_25"
        android:layout_height="@dimen/dp_25"
        android:src="@mipmap/zuan_02" />

</FrameLayout>

调用:

if (ivMine.getVisibility() == View.VISIBLE) {
    ivMine.startAnimation(sato1);
}else {
    ivMine2.startAnimation(sato1);
}

如果想实现无限翻转的效果,只需要让handler循环发消息即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值