利用android实现了简单旋转动画,效果如下,从左到右,3个状态,最终图片旋转180度:
2012-6-18 11:18 上传 下载附件 (19.54 KB)
2012-6-18 11:19 上传 下载附件 (16.33 KB)

  旋转动画利用的是RotateAnimation实现的。布局文件main.xml代码:
?
代码片段,双击复制
01 02 03 04 05 06 07 08 09 10 11   <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方法如下:
?
代码片段,双击复制
01 02 03 04 05 06 07 08 09 10    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);   }

  解释一下:
   ?
代码片段,双击复制
01 new RotateAnimation( 0 , 180 , centerX,centerY);

  第一个参数表示动画的起始角度,第二个参数表示动画的结束角度,第三个表示动画的旋转中心x轴,第四个表示动画旋转中心y轴。
  ?
代码片段,双击复制
01  rotateAnimation.setDuration( 1000 * 20 );

  表动画持续20s。
   ?
代码片段,双击复制
01 rotateAnimation.setFillAfter( true );

  ture表示动画结束后停留在动画的最后位置,false表示动画结束后回到初始位置,默认为false。
?
代码片段,双击复制
01   mView.startAnimation(rotateAnimation);


  
  
  

更多相关文章

  1. android之组件1
  2. 另一个更简单的Android应用程序全屏的方法
  3. Android安卓51个开源代码
  4. 系出名门Android(6) - 控件(View)
  5. 常用的android权限配置和常用工具代码
  6. Android(安卓)Pull解析xml
  7. Android(安卓)5.1状态栏背景色定制 在Launcher3界面显示透明,在其
  8. ViewPager实现一个页面多个Item的显示
  9. Android动画之Interpolator

随机推荐

  1. [置顶] Android(安卓)popwindow和fragmen
  2. android 源码设计模式之--代理模式(Proxy
  3. Android(安卓)UI总结 Android(安卓)和H5
  4. Android自定义控件系列案例【二】
  5. Android(安卓)Framework学习(六)之RefBas
  6. android 蓝牙搜索不到Ble设备
  7. Android简单转盘的实现
  8. 我的《Android官方开发文档Training系列
  9. Android串口开发初体验(windows开发环境)
  10. Android音频采集