前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >仿美团首页底部标签 斜上方循环动画

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

作者头像
Jingbin
发布2022-01-05 14:58:14
5200
发布2022-01-05 14:58:14
举报
文章被收录于专栏:Android 技术栈Android 技术栈

主要有三小点需要注意:

  • 1.旋转动画设置好圆心
  • 2.延迟一秒后再执行动画
  • 3.使用view.startAnimation(animation);执行动画,不然第二次会无效
代码语言:javascript
复制
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);
        }
    }
};
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021.11.26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档