利用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讲义2之输入界面
  2. android中的帧动画
  3. android 学习笔记: manifest.xml中声明多个activity的方法记录
  4. android中的帧动画
  5. android 动画
  6. android logo:内核、android开机动画
  7. android简单Logo
  8. Activity切换动画无效(android:windowIsTranslucent)影响(androi
  9. android 如何判断软件是否第一次运行?

随机推荐

  1. Android不让弹出键盘挡住View
  2. android图像处理系列之三--图片色调饱和度
  3. [原]android 中如何飞行模式的几个操作
  4. 进度条及拖动条背景颜色设置(progressDraw
  5. Android(安卓)windowSoftInputMode属性解
  6. android---------ndk中的各个版本的下载
  7. Android(安卓)中文 API (100) —— Scrol
  8. android intent的常用方法
  9. ANDROID轻量级JSON序列化和反序列化[转]
  10. Android(安卓)WebView总结