package cn.edu.animtest;import android.app.Activity;import android.os.Bundle;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.ImageView;public class AnimTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Animation myAnimation= AnimationUtils.loadAnimation(this,R.anim.anim);//加载动画 ImageView myImageView = (ImageView) this.findViewById(R.id.myImageView);//得到ImageView的引用 myImageView.startAnimation(myAnimation);//启动动画 }}
?在res文件夹下,新建anim.xml文件
?
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="8000" /> <!-- 透明度的变换 --> <scale android:interpolator= "@android:anim/accelerate_decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.4" android:fromYScale="0.0" android:toYScale="1.4" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="10000" /> <!-- 尺寸的变换 --> <translate android:fromXDelta="30" android:toXDelta="0" android:fromYDelta="30" android:toYDelta="50" android:duration="10000" /> <!-- 尺位置的变换 --> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="0" android:toDegrees="+350" android:pivotX="50%" android:pivotY="50%" android:duration="10000" /> <!-- 旋转变换 --></set>?
再布局文件中,增加ImageView
?
<ImageView android:id="@+id/myImageView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/icon"/>?
?