栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

主要有三小点需要注意:

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


public void showAnimal(ImageView imageView, Handler handler) {
    this.imageView = imageView;
    this.handler = handler;
    handler.postDelayed(hideRunnable, 300);
}


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);
        }
    }
};
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/601653.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号