android 后台代码设置动画
2015-08-03 18:31
351 查看
1、设置旋转动画final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF,0.5f);
在xml文件中定义Interpolatorandroid:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true"这样所有的Animation共用一个Interpolator。在代码中用代码设置如下anim.setInterpolator(new AccelerateInterpolator());在new一个AnimationSet中传入true则所有的Animation共用Interpolator。
animation.setInterpolator(new LinearInterpolator()); // LinearInterpolator 表示均匀速率 animation.setDuration(3000);//设置动画持续时间 animation.setRepeatCount(Animation.INFINITE); //表示重复多次,也可以用具体的次数 ll_earn_circle_bg.startAnimation(animation); //ll_earn_circle_bg 是一个LinearLayout控件 2、设置位移动画
/** * CycleTimes动画重复的次数 * @param CycleTimes */ public void shakeAnimation(int CycleTimes) { if (null == mShakeAnimation) { mShakeAnimation = new TranslateAnimation(0, 10, 0, 0); mShakeAnimation.setInterpolator(new CycleInterpolator(CycleTimes)); //设置速度,,CycleInterpolator某种数学上的曲线,即摇晃的速率曲线化 mShakeAnimation.setDuration(1500); mShakeAnimation.setRepeatMode(Animation.REVERSE);//设置反方向执行 } tv_curmoney.startAnimation(mShakeAnimation); //tv_curmoney是一个textview控件 }
3、设置缩放动画
/** 设置缩放动画 */ final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(2000);//设置动画持续时间 iv_go_rank.startAnimation(animation); // iv_go_rank 是一个imageview控件
关于速率的介绍:
在xml文件中定义Interpolatorandroid:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true"这样所有的Animation共用一个Interpolator。在代码中用代码设置如下anim.setInterpolator(new AccelerateInterpolator());在new一个AnimationSet中传入true则所有的Animation共用Interpolator。
相关文章推荐
- Android Studio 修改 包名 package name
- android之SharedPreferences
- Android复习笔记(9) - 调用远程服务
- Android复习笔记(8) - 服务(Service)
- Android 关于引用jackson的jar包混淆报错或打包后运行报错崩溃
- Android发送短信
- Android复习笔记(7) -发送广播
- Android复习笔记(6) -BrodCastReceiver (广播接收者
- Actvity的启动模式相关(转)
- android控件的事件传播机制
- Android复习笔记(5)-数据库操作 sqllite
- Android复习笔记(4) - 文件读取相关
- Android复习笔记(3)-android下的junit
- Android图片缩放库 Photoview 和 Gif 控件GifView 的使用
- Android拨号
- Android复习笔记(2) - Intent介绍
- android复习笔记(1) - Activity相关
- AndroidStudio com.android.dex.dexException
- Android 自定义ViewGroup布局控件,垂直滚动引导
- Android:OptionMenu