android Animation开发实例
1、新建一个android工程,名称AnimationShow,其他参数可以自己配置,之后点击完成,生成项目


2、在main.xml中配置三个按钮和一个图片控件
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:text="移动动画"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:text="旋转动画"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:text="透明度"/>
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:scaleType="matrix"
android:src="@drawable/info" >
</ImageView>

3、配置移动动画的配置文件move.xml 在layout文件夹下
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:repeatCount="2" //动画重复次数
android:fromXDelta="-30" // 属性为动画起始时 X坐标上的伸缩尺寸
android:fromYDelta="-30" // 属性为动画起始时 Y坐标上的伸缩尺寸
android:toXDelta="-80" //属性为动画结束时 X坐标上的伸缩尺寸
android:toYDelta="200" // 属性为动画结束时 Y坐标上的伸缩尺寸
android:duration="3000" //持续时间
/>
</set>

4、配置旋转动画的配置文件rotate.xml 在layout文件夹下
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
// 加速-动画插入器
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="2" //重复次数
android:fromDegrees="0" //fromDegrees 为动画起始时物件的角度
android:toDegrees="+270" //当角度为正数——表示顺时针旋转
android:pivotX="50%" //为动画相对于物件的X、Y坐标的开始位
android:pivotY="50%"
android:duration="3000" //持续时间
/>
</set>
5、配置透明度动画配置文件see.xml,实现透明度的展示,在layout文件夹下
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="1000" //持续时间
android:fromAlpha="0.1" //之前的透明度
android:repeatCount="infinite" //有限次数
android:repeatMode="reverse" //模式反转
android:toAlpha="1.0" > //目标透明度
</alpha>
</set>

6、在主体函数中添加,按钮和事件响应函数,以及对应的动画展示。主要代码:
imageView=(ImageView)this.findViewById(R.id.myImageView);
one.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
Animation ani = AnimationUtils.loadAnimation(getApplicationContext(), R.layout.move);
imageView.startAnimation(ani);
}
});



7、运行程序,可以看见效果图,依次展示动画的移动,旋转,透明度变化




