动画工具类

  1 public class AbAnimationUtil {
  2
  3     /** 定义动画的时间. */
  4     public final static long aniDurationMillis = 1L;
  5
  6     /**
  7      * 用来改变当前选中区域的放大动画效果
  8      * 从1.0f放大1.2f倍数
  9      *
 10      * @param view the view
 11      * @param scale the scale
 12      */
 13     public static void largerView(View view, float scale) {
 14         if (view == null)
 15             return;
 16
 17         // 置于所有view最上层
 18         view.bringToFront();
 19         int width = view.getWidth();
 20         float animationSize = 1 + scale / width;
 21         scaleView(view, animationSize);
 22     }
 23
 24     /**
 25      * 用来还原当前选中区域的还原动画效果.
 26      *
 27      * @param view the view
 28      * @param scale the scale
 29      */
 30     public static void restoreLargerView(View view, float scale) {
 31         if (view == null)
 32             return;
 33         int width = view.getWidth();
 34         float toSize = 1 + scale / width;
 35         // 从1.2f缩小1.0f倍数
 36         scaleView(view, -1 * toSize);
 37     }
 38
 39     /**
 40      * 缩放View的显示.
 41      *
 42      * @param view 需要改变的View
 43      * @param toSize 缩放的大小,其中正值代表放大,负值代表缩小,数值代表缩放的倍数
 44      */
 45     private static void scaleView(final View view, float toSize) {
 46         ScaleAnimation scale = null;
 47         if (toSize == 0) {
 48             return;
 49         } else if (toSize > 0) {
 50             scale = new ScaleAnimation(1.0f, toSize, 1.0f, toSize,
 51                     Animation.RELATIVE_TO_SELF, 0.5f,
 52                     Animation.RELATIVE_TO_SELF, 0.5f);
 53         } else {
 54             scale = new ScaleAnimation(toSize * (-1), 1.0f, toSize * (-1),
 55                     1.0f, Animation.RELATIVE_TO_SELF, 0.5f,
 56                     Animation.RELATIVE_TO_SELF, 0.5f);
 57         }
 58         scale.setDuration(aniDurationMillis);
 59         scale.setInterpolator(new AccelerateDecelerateInterpolator());
 60         scale.setFillAfter(true);
 61         view.startAnimation(scale);
 62     }
 63
 64     /**
 65      * 跳动-跳起动画.
 66      *
 67      * @param view the view
 68      * @param offsetY the offset y
 69      */
 70     private void playJumpAnimation(final View view,final float offsetY) {
 71         float originalY = 0;
 72         float finalY = - offsetY;
 73         AnimationSet animationSet = new AnimationSet(true);
 74         animationSet.addAnimation(new TranslateAnimation(0, 0, originalY,finalY));
 75         animationSet.setDuration(300);
 76         animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
 77         animationSet.setFillAfter(true);
 78
 79         animationSet.setAnimationListener(new AnimationListener() {
 80
 81             @Override
 82             public void onAnimationStart(Animation animation) {
 83             }
 84
 85             @Override
 86             public void onAnimationRepeat(Animation animation) {
 87             }
 88
 89             @Override
 90             public void onAnimationEnd(Animation animation) {
 91                 playLandAnimation(view,offsetY);
 92             }
 93         });
 94
 95         view.startAnimation(animationSet);
 96     }
 97
 98     /**
 99      * 跳动-落下动画.
100      *
101      * @param view the view
102      * @param offsetY the offset y
103      */
104     private void playLandAnimation(final View view,final float offsetY) {
105         float originalY =  - offsetY;
106         float finalY = 0;
107         AnimationSet animationSet = new AnimationSet(true);
108         animationSet.addAnimation(new TranslateAnimation(0, 0, originalY,finalY));
109         animationSet.setDuration(200);
110         animationSet.setInterpolator(new AccelerateInterpolator());
111         animationSet.setFillAfter(true);
112
113         animationSet.setAnimationListener(new AnimationListener() {
114
115             @Override
116             public void onAnimationStart(Animation animation) {
117             }
118
119             @Override
120             public void onAnimationRepeat(Animation animation) {
121             }
122
123             @Override
124             public void onAnimationEnd(Animation animation) {
125                 //两秒后再调
126                 view.postDelayed(new Runnable(){
127
128                     @Override
129                     public void run(){
130                         playJumpAnimation(view,offsetY);
131                     }
132                 }, 2000);
133             }
134         });
135
136         view.startAnimation(animationSet);
137     }
138
139     /**
140      * 旋转动画
141      * @param v
142      * @param durationMillis
143      * @param repeatCount  Animation.INFINITE
144      * @param repeatMode  Animation.RESTART
145      */
146     public static void playRotateAnimation(View v,long durationMillis,int repeatCount,int repeatMode) {
147
148         //创建AnimationSet对象
149         AnimationSet animationSet = new AnimationSet(true);
150         //创建RotateAnimation对象
151         RotateAnimation rotateAnimation = new RotateAnimation(0f,+360f,
152                     Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
153         //设置动画持续
154         rotateAnimation.setDuration(durationMillis);
155         rotateAnimation.setRepeatCount(repeatCount);
156         //Animation.RESTART
157         rotateAnimation.setRepeatMode(repeatMode);
158         //动画插入器
159         rotateAnimation.setInterpolator(v.getContext(), android.R.anim.decelerate_interpolator);
160         //添加到AnimationSet
161         animationSet.addAnimation(rotateAnimation);
162
163         //开始动画
164         v.startAnimation(animationSet);
165     }
166
167 }
时间: 2024-08-24 07:38:55

动画工具类的相关文章

Cocos2d-x动画工具类

1.此工具类的目的是为了方便执行动画,使用TexturePackerGUI工具可以导出plist文件和png图片,这里我示例图片叫bxjg.plist和bxjg.png //////////////////////////////////////.h文件 #ifndef _AnimateUtil_H_ #define _AnimateUtil_H_ #include "cocos2d.h" using namespace cocos2d; using namespace std; cl

Android两个页面之间的切换效果工具类

import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Build; import android.widget.Toast; public class ActivityAnimationUtil { private Context context; pr

实用工具类--第三方开源--Lazy

下载地址 :https://github.com/ddwhan0123/Lazy 工具 描述 AnimationUtils 动画工具类 AppUtils APP相关信息工具类 AssetDatabaseOpenHelper 目录资源获取 Base64 加密 BitmapUtil 获取Bitmap和对Bitmap的操作 ChannelUtil 获取市场号 Colors 颜色工具类 包括常用的色值 DES DES加密解密类 DataCleanManager 本应用数据清除管理器 DatabaseEx

史上最全的开发工具类

    API 银行卡管理 → BankCheck checkBankCard : 校验银行卡卡号是否合法 getBankCardCheckCode: 从不含校验位的银行卡卡号采用 Luhm 校验算法获得校验位 getNameOfBank : 通过银行卡的前六位确定判断银行开户行及卡种 SharePreference缓存数据 →AppSharePreferenceMgr put : 保存数据的方法 get : 获取数据的方法 putImage: 保存图片到SharedPreferences ge

史上最全的开发工具类(转)

     API 银行卡管理 → BankCheck checkBankCard : 校验银行卡卡号是否合法getBankCardCheckCode: 从不含校验位的银行卡卡号采用 Luhm 校验算法获得校验位getNameOfBank : 通过银行卡的前六位确定判断银行开户行及卡种 SharePreference缓存数据 →AppSharePreferenceMgr put : 保存数据的方法get : 获取数据的方法putImage: 保存图片到SharedPreferencesgetIma

iOS开发--QQ音乐练习,旋转动画的实现,音乐工具类的封装,定时器的使用技巧,SliderBar的事件处理

一.旋转动画的实现 二.音乐工具类的封装 -- 返回所有歌曲,返回当前播放歌曲,设置当前播放歌曲,返回下一首歌曲,返回上一首歌曲方法的实现 头文件 .m文件 1 #import "ChaosMusicTool.h" 2 #import "MJExtension.h" 3 #import "ChaosMusic.h" 4 5 static NSArray *_musics; 6 static ChaosMusic *_playingMusic; 7

Unity+NGUI打造网络图片异步加载与本地缓存工具类(一)

我们在移动端的开发中,异步网络图片加载用的非常的多,在unity当中虽然有AssetBundle的存在,一般是先加载好游戏资源然后再进入场景,但是还有不少地方能够用到异步网络图片的加载以及其缓存机制. 我之前也写过两个版本的ios中的异步网络图片加载helper类,所以今天按照同样的思路,也想做一个好用的helper类给大家使用以及简单的说下实现原理. 首先我们加载一张网络图片,要做的事情分步来讲为: 0.开始之前设置一张固定的图片作为占位图(placeholder),表示我们的图片还没加载好,

AS3的大量实用工具类、开源包,该帖绝对值得你收藏!

ActionScriptUtility Class Tweener Tweening Platform tween24 – 一位日本人写的tween库 Tweener Audio as3soundeditorlib ASAudio – 小巧的声音处理库 SoundAS – 实用的声音管理库 Graphic as3-bitmap-mosaic-class graffiti Volumetrics – 一款实时光照效果库 Component Minimalcomps – 小巧的纯AS组件库 Skin

拍照、本地图片工具类(兼容至Android7.0)

拍照.本地图片工具类:解决了4.4以上剪裁会提示"找不到文件"和6.0动态授予权限,及7.0报FileUriExposedException异常问题. package com.hb.weex.util; import android.Manifest; import android.app.Activity; import android.app.Dialog; import android.content.ClipData; import android.content.Conten