fromAlpha开始透明度 toAlpha结束透明度
fillAfter与fillBefore指定最终是与开始还是结束样式相同
android:pivotY="50%" 相对于自身 写成android:pivotY="50%p"则是相对于父容器
1res下新建anim文件夹(Animation缩写)
new 5个xml 文件名自定 类型 alpha rotae set等每个都建一个
alpha_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:fromAlpha="0.5"
android:startOffset="1000"
android:toAlpha="1.0" >
</alpha>
rotate_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" >
</rotate>
scale_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:fromXScale="0.2"
android:fromYScale="0.2"
android:toXScale="2.0"
android:toYScale="2.0" >
</scale>
set_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="2000"
android:fillAfter="true"
android:fromAlpha="0.5"
android:startOffset="1000"
android:toAlpha="1.0" >
<rotate
android:duration="2000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" >
</rotate>
</alpha>
</set>
translate_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXDelta="20%p"
android:fromYDelta="0"
android:repeatCount="2"
android:repeatMode="reverse"
android:toXDelta="50%p"
android:toYDelta="50%p" >
</translate>
2MainActivity
package com.example.a113xmlanimation;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
}
/**
* 透明度变化
*/
public void click1(View view) {
Animation animation = AnimationUtils.loadAnimation(this,
R.anim.alpha_anim);
iv.startAnimation(animation);
}
/**
* 缩放
*/
public void click2(View view) {
Animation animation = AnimationUtils.loadAnimation(this,
R.anim.scale_anim);
iv.startAnimation(animation);
}
/**
* 旋转
*/
public void click3(View view) {
Animation animation = AnimationUtils.loadAnimation(this,
R.anim.rotate_anim);
iv.startAnimation(animation);
}
/**
* 平移
*/
public void click4(View view) {
Animation animation = AnimationUtils.loadAnimation(this,
R.anim.translate_anim);
iv.startAnimation(animation);
}
/**
* 组合动画
*/
public void click5(View view) {
Animation animation = AnimationUtils.loadAnimation(this,
R.anim.set_anim);
iv.startAnimation(animation);
}
}