美文网首页
Android ObjectAnimator 控件抖动效果

Android ObjectAnimator 控件抖动效果

作者: wenju | 来源:发表于2021-02-24 10:21 被阅读0次

控件抖动效果,包含放大缩小旋转以及循环判断

      /**
     * 动画抖动效果
     * @param view 抖动控件
     * @param scaleLarge 缩小倍数
     * @param shakeDegrees 放大倍数
     * @param duration 抖动角度
     * @param isInfinite 是否循环抖动
     */
    private void startShakeByPropertyAnim(View view, float scaleSmall, float scaleLarge, float shakeDegrees, long duration,boolean isInfinite) {
        if (view == null) {
            return;
        }

        PropertyValuesHolder scaleXValuesHolder = PropertyValuesHolder.ofKeyframe(View.SCALE_X,
                Keyframe.ofFloat(0f, 1.0f),
                Keyframe.ofFloat(0.25f, scaleSmall),
                Keyframe.ofFloat(0.5f, scaleLarge),
                Keyframe.ofFloat(0.75f, scaleLarge),
                Keyframe.ofFloat(1.0f, 1.0f)
        );
        PropertyValuesHolder scaleYValuesHolder = PropertyValuesHolder.ofKeyframe(View.SCALE_Y,
                Keyframe.ofFloat(0f, 1.0f),
                Keyframe.ofFloat(0.25f, scaleSmall),
                Keyframe.ofFloat(0.5f, scaleLarge),
                Keyframe.ofFloat(0.75f, scaleLarge),
                Keyframe.ofFloat(1.0f, 1.0f)
        );

        PropertyValuesHolder rotateValuesHolder = PropertyValuesHolder.ofKeyframe(View.ROTATION,
                Keyframe.ofFloat(0f, 0f),
                Keyframe.ofFloat(0.1f, -shakeDegrees),
                Keyframe.ofFloat(0.2f, shakeDegrees),
                Keyframe.ofFloat(0.3f, -shakeDegrees),
                Keyframe.ofFloat(0.4f, shakeDegrees),
                Keyframe.ofFloat(0.5f, -shakeDegrees),
                Keyframe.ofFloat(0.6f, shakeDegrees),
                Keyframe.ofFloat(0.7f, -shakeDegrees),
                Keyframe.ofFloat(0.8f, shakeDegrees),
                Keyframe.ofFloat(0.9f, -shakeDegrees),
                Keyframe.ofFloat(1.0f, 0f)
        );

        ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(view, scaleXValuesHolder, scaleYValuesHolder, rotateValuesHolder);
        objectAnimator.setDuration(duration);
        if(isInfinite){
            objectAnimator.setRepeatCount(Animation.INFINITE);
        }
        objectAnimator.start();
    }

相关文章

  • Android ObjectAnimator 控件抖动效果

    控件抖动效果,包含放大缩小旋转以及循环判断

  • ObjectAnimator基本使用

    Android自定义控件三部曲文章索引 ObjectAnimator基本使用

  • iOS控件抖动效果

    方案一: 方案二 两个方案设置了同样的数据最后的显示结果也不太一样,目前还不清楚原因。 对应.m文件

  • 属性动画源码解析

    这里主要研究ObjectAnimator 是如何改变控件的属性 用法 我们来看ObjectAnimator.ofF...

  • View控件的抖动效果

    一、前言:我们在实现账号或者密码输入的时候,经常有错误校验,有时候我们会弹出一个 Toast 来提示用户,有一个更...

  • Android防自定控件抖动

    在最近的项目中碰到需要用手指控制View移动的需求,实现的过程中发现View会随着手指的移动而抖动,并且抖动程度随...

  • Android 实现 EditText抖动效果

    一、前言: 我们在实现账号或者密码输入的时候,经常有错误校验,有时候我们会弹出一个 Toast 来提示用户,有一个...

  • Android 实现 EditText抖动效果

    一、前言: 我们在实现账号或者密码输入的时候,经常有错误校验,有时候我们会弹出一个 Toast 来提示用户,有一个...

  • 2020-05-20 二级列表条目显示功能Expandabl

    android系统控件ExpandableListView默认显示效果的实现: 效果图见这个链接:系统默认显示效果...

  • Android 进度控件

    Android 进度控件 Android 圆形、半圆形进度效果、半圆SeekBar、刻度尺效果实现代码下载:Git...

网友评论

      本文标题:Android ObjectAnimator 控件抖动效果

      本文链接:https://www.haomeiwen.com/subject/nggjfltx.html