仿美团首页底部标签 斜上方循环动画

主要有三小点需要注意:

  • 1.旋转动画设置好圆心
  • 2.延迟一秒后再执行动画
  • 3.使用view.startAnimation(animation);执行动画,不然第二次会无效
private ImageView imageView;
private Handler handler;
private RotateAnimation animation;

/**
 * 给view设置动画
 */
public void showAnimal(ImageView imageView, Handler handler) {
    this.imageView = imageView;
    this.handler = handler;
    handler.postDelayed(hideRunnable, 300);
}

/**
 * 停止view动画
 */
public void stopAnimal() {
    if (imageView != null) {
        imageView.clearAnimation();
        if (animation != null) {
            animation.cancel();
        }
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
    }
}

private final Runnable hideRunnable = new Runnable() {
    @Override
    public void run() {
        if (animation == null) {
            animation = new RotateAnimation(0f, -10f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f);
            animation.setDuration(200);//设置动画持续时间
            animation.setInterpolator(new LinearInterpolator());//不停顿
            animation.setRepeatMode(ValueAnimator.REVERSE);//重新从头执行
            //animation.setRepeatCount(ValueAnimator.INFINITE);//设置重复次数
            animation.setRepeatCount(1);//设置重复次数
            animation.setAnimationListener(new AnimationListenerAdapter() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    if (handler != null) {
                        handler.removeCallbacks(hideRunnable);
                        handler.postDelayed(hideRunnable, 1000);
                    }
                }
            });
            if (imageView != null) {
                imageView.setAnimation(animation);
            }
        }
        if (imageView != null) {
            imageView.startAnimation(animation);
        }
    }
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值