Android实现动画旋转的源代码

Android实现旋转动画利用的是RotateAnimation实现的。布局文件main.xml代码:
01    <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
02    android:orientation="vertical" android:id="@+id/mContener"
03    android:layout_width="fill_parent"
04    android:layout_height="fill_parent"
05    >
06    <imageview android:id="@+id/picture_tiankong"
07    android:layout_width="fill_parent"
08    android:layout_height="fill_parent"
09    android:src="@drawable/tiankong"
10    android:onClick="showAnimation"
11    />
  android:onClick="showAnimation" 代码作用是在点击ImageView的时候,调用MainActivity中的showAnimation方法,showAnimation方法如下:
01    public void showAnimation(View view) {
02    Log.v(TAG, "showContent>>>");
03    final float centerX = mView.getWidth() / 2.0f;
04    final float centerY = mView.getHeight() / 2.0f;
05    RotateAnimation rotateAnimation = new RotateAnimation(0, 180, centerX,
06    centerY);
07    rotateAnimation.setDuration(1000 * 20);
08    rotateAnimation.setFillAfter(true);
09    mView.startAnimation(rotateAnimation);
10    }
  解释一下:
1    new RotateAnimation(0, 180, centerX,centerY);
  第一个参数表示动画的起始角度,第二个参数表示动画的结束角度,第三个表示动画的旋转中心x轴,第四个表示动画旋转中心y轴。
1    rotateAnimation.setDuration(1000 * 20);
  表动画持续20s。
1    rotateAnimation.setFillAfter(true);
  ture表示动画结束后停留在动画的最后位置,false表示动画结束后回到初始位置,默认为false。
1    mView.startAnimation(rotateAnimation);

Android相关内容:

posted on 2013-02-20 10:09  itstrike  阅读(1053)  评论(0编辑  收藏  举报

导航