利用android实现了简单旋转动画,效果如下,从左到右,3个状态,最终图片旋转180度:

旋转动画利用的是RotateAnimation实现的。布局文件main.xml代码:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:id="@+id/mContener"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >    <imageview android:id="@+id/picture_tiankong"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:src="@drawable/tiankong"    android:onClick="showAnimation"    />     android:onClick="showAnimation" 代码作用是在点击ImageView的时候,调用MainActivity中的showAnimation方法,showAnimation方法如下:     public void showAnimation(View view) {    Log.v(TAG, "showContent>>>");    final float centerX = mView.getWidth() / 2.0f;    final float centerY = mView.getHeight() / 2.0f;    RotateAnimation rotateAnimation = new RotateAnimation(0, 180, centerX,    centerY);    rotateAnimation.setDuration(1000 * 20);    rotateAnimation.setFillAfter(true);    mView.startAnimation(rotateAnimation);    }

解释一下:

new RotateAnimation(0, 180, centerX,centerY);

第一个参数表示动画的起始角度,第二个参数表示动画的结束角度,第三个表示动画的旋转中心x轴,第四个表示动画旋转中心y轴。

rotateAnimation.setDuration(1000 * 20);

表动画持续20s。

rotateAnimation.setFillAfter(true);

ture表示动画结束后停留在动画的最后位置,false表示动画结束后回到初始位置,默认为false。

mView.startAnimation(rotateAnimation);


源码下载

更多相关文章

  1. Android(安卓)Activity界面切换添加动画特效
  2. android实现字体闪烁动画的方法
  3. Android(安卓)matrix 控制图片的旋转、缩放、移动
  4. [Android(安卓)NDK]Android(安卓)JNI开发例子 ---3 在JNI中实现o
  5. Android(安卓)Vibrator使用
  6. Android:interpolator用法
  7. android 自定义view
  8. 创建android逐帧动画的两种方式
  9. Android(安卓)Activity界面切换添加动画特效

随机推荐

  1. android 该文件包与具有同一名称的现有文
  2. Android软件开发之盘点界面五大布局(十六)
  3. Android多Module开发,最终打包成一个aar对
  4. 如何恢复(初始化)android studio所有设置
  5. 【Android适配器系列】BaseAdapter学习笔
  6. 三星给中国电信定制的支持Android(安卓)2
  7. Android中的动态加载机制
  8. Android(安卓)P zygote 原理分析之app_pr
  9. 什么时候会启动多个进程
  10. 如何检查 Android(安卓)应用的内存使用情