第一种:
代码继承Animation实现
package com.iaiai.an;import android.graphics.Matrix;import android.view.animation.Animation;import android.view.animation.LinearInterpolator;import android.view.animation.Transformation;/** *  * <br/> * Title: WindowAnimation.java<br/> * E-Mail: 176291935@qq.com<br/> * QQ: 176291935<br/> * Http: iaiai.iteye.com<br/> * Create time: 2013-8-27 上午10:22:22<br/> * <br/> *  * @author 丸子 * @version 0.0.1 */public class WindowAnimation extends Animation {private int halfWidth;private int halfHeight;private int duration;public WindowAnimation(int duration) {this.duration = duration;}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) {super.applyTransformation(interpolatedTime, t);Matrix matrix = t.getMatrix();//matrix.preScale(interpolatedTime, interpolatedTime);matrix.preRotate(interpolatedTime * 360); // 进行旋转matrix.preTranslate(-halfWidth, -halfHeight); // 改变动画的起始位置,把扩散点和起始点移到中间matrix.postTranslate(halfWidth, halfHeight);}@Overridepublic void initialize(int width, int height, int parentWidth, int parentHeight) {super.initialize(width, height, parentWidth, parentHeight);this.setDuration(duration);this.setFillAfter(true);this.halfHeight = height / 2;this.halfWidth = width / 2;this.setInterpolator(new LinearInterpolator());}}


@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);final Animation animation = new WindowAnimation(1000);animation.setRepeatCount(-1);//执行多少次findViewById(R.id.btn).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {findViewById(R.id.imageView1).setAnimation(animation);animation.start();}});}



第二种:
在xml中配置
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <rotate        android:duration="1000"        android:fromDegrees="0"        android:interpolator="@android:anim/accelerate_decelerate_interpolator"        android:pivotX="50%"        android:pivotY="50%"        android:repeatCount="-1"        android:shareInterpolator="true"        android:toDegrees="+360" />    <!--rotate 旋转动画效果    repeatCount 旋转次数===========================interpolator 指定一个动画的插入器,用来控制动画的速度变化   AccelerateInterpolator:动画开始时比较慢,然后逐渐加速。DecelerateInterpolator:动画开始时比较快,然后逐渐减速。AccelerateDecelerateInterpolator:动画开始时和结束时比较慢,中间过程加速。LinearInterpolator:动画匀速进行。CycleInterpolator:动画循环播放指定次数,速率沿着正弦曲线改变。)=============================fromDegrees 属性为动画起始时物件的角度     toDegrees 属性为动画结束时物件旋转的角度,+代表顺时针    duration 属性为动画持续时间,以毫秒为单位pivotX/pivotY 属性为动画旋转中心位置shareInterpolator     --></set>


@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);final Animation animation = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.xz);findViewById(R.id.btn).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {findViewById(R.id.imageView1).setAnimation(animation);animation.start();}});}

更多相关文章

  1. Android的Spinner组件的XML属性(备查)
  2. Android(安卓)五大布局之(一) 线性布局和相对布局
  3. Android(安卓)解析XML
  4. Android(安卓)播放Gif 动画
  5. Android遍历API (1) 动画篇——克隆动画AnimationCloning
  6. Android(安卓)12上全新的应用启动画面,还不适配一下?
  7. android 动态 布局
  8. Android属性动画(ObjectAnimation)
  9. Android沉浸式状态栏,看完这篇就够了!

随机推荐

  1. AndroidManifest中activity属性参数设置
  2. android 去除 除了当前白名单的app
  3. Android(安卓)获取ip地址
  4. Android实现日历
  5. binder编译error
  6. android的进度条相关知识
  7. android 网络拨号流程
  8. Android官方入门文档[4]启动另一个Activi
  9. android系统中自带的图标大全
  10. Android实现日历