动画小探
来源:互联网 发布:优化网站排名的步骤 编辑:程序博客网 时间:2024/05/22 00:47
01)旋转及淡入淡出效果的动画,简单代码如下:
import android.animation.Animator.AnimatorListener;import android.animation.ValueAnimator;private ValueAnimator animator = null;/** * 初始化转盘的属性动画 */private void initAnimator() { animator = ValueAnimator.ofFloat(0f, 360.0f); animator.setRepeatCount(ValueAnimator.INFINITE); animator.setInterpolator(new AccelerateDecelerateInterpolator()); //LinearInterpolator animator.setDuration(4000); animator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); mGradientAnimation.setRotation(value); //设置旋转角度 float alpa = (float)(value/360); if (value < 180) { mGradientIcon.setAlpha(alpa);//设置蒙版度 } else { mGradientIcon.setAlpha(1 - alpa); } } });}/*开始旋转动画*/private void startGradientAnimation() { if (animator == null) initAnimator(); if (!animator.isStarted()) { animator.start(); } else { animator.resume(); }}/*暂停旋转动画*/private void pauseGradientAnimation() { if (animator!= null && animator.isRunning()) { animator.pause(); }}/*复位旋转动画*/private void stopGradientAnimation() { if (animator != null) { animator.cancel(); } mGradientAnimation.setRotation(0); mGradientIcon.setAlpha(1.0f);}
02)更多动画详情,可参考http://www.2cto.com/kf/201410/342375.html
各种动画介绍的都很详细 ,如缩放动画如下:
//方式一通过代码的方式定义缩放动画
AnimationscaleAnimation=new ScaleAnimation(0.5f, 1.0f,1.0f, 1.0f);
scaleAnimation.setDuration(2000);//设置动画持续时间为3秒
scaleAnimation.setFillAfter(true);//设置动画结束后保持当前的位置(即不返回到动画开始前的位置)
scaleAnimation.setRepeatCount(3);
imgShow.startAnimation(scaleAnimation);
//方式二通过在xml中定义缩放动画
第一步:定义xml动画文件:scale.xml
“1.0”encoding=”utf-8”?>
“http://schemas.android.com/apk/res/android”
android:fromXScale=”0.5”
android:toXScale=”1.0”
android:fromYScale=”1.0”
android:toYScale=”1.0”
android:duration=”3000”
android:fillAfter=”true”>
第二步:加载xml动画文件并将其设置到指定的View上
AnimationscaleAnimation2=AnimationUtils.loadAnimation(this, R.anim.scale);//加载Xml文件中的动画
imgShow.startAnimation(scaleAnimation2);
03)为某个动画添加监听器,如:
mAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { finish(); }});
- 动画小探
- 一个小动画(源代码)
- 示波器小动画
- jQuery实现小动画
- 小动画练习
- SeaJS实例小动画
- 一个小动画
- CSS3加载小动画
- 动画小例子
- 属性动画小笔记
- CSS3 小动画
- HTML5 小动画例子
- ObjectAnimator 动画小技巧
- css3 animation小动画
- 一个loading小动画
- 动画封装小案例
- SVG淋浴小动画
- 简单的小动画
- 当你在浏览器地址栏输入一个URL后回车,将会发生的事情? (转)
- Linux笔记(53)——for循环
- 成为Java GC专家(4)
- 预编译之条件编译和宏
- 安卓吧
- 动画小探
- percona-toolkit使用方法
- RecyclerView封装——添加Header、Footer(在网格瀑布流布局中独占一行)
- 手把手教你实现百度基础地图+定位功能+设置中心点+添加Marker
- Scala之Case Class
- java反射的一些调试
- Have Lunch Together
- 哈希冲突之散列法
- MySQL 中的 ERROR 1366 (Mac)