您的位置:首页 > 移动开发 > Android开发

android动画(Animation)

2015-08-09 23:21 381 查看
AlphaAnimation 透明度

AlphaAnimationalphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(1000);
alphaButton.startAnimation(alphaAnimation);

<?xml
version="1.0"encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1000">
</alpha>

RotateAnimation 角度

//RotateAnimation rotateAnimation = new RotateAnimation(0, 360, 50,
// 50);//50,50是相对控件自身的XY偏移量
RotateAnimationrotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,//
旋转点X坐标相对于自身比例一半的位置
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(1000);
rotateButton.startAnimation(rotateAnimation);
// 调用Xml资源
rotateButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.ro));

<?xml
version="1.0"encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="1000"
android:pivotX="50%"
android:pivotY="50%">
</rotate>

ScaleAnimation 缩放

ScaleAnimationscaleAnimation = new ScaleAnimation(1, 1.5f, 1, 2,//x方向由1放大到1.5,y方向由1放大到2
Animation.RELATIVE_TO_SELF, 0.5f,//放大中心点X坐标在一半处
Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(1000);
scaleButton.startAnimation(scaleAnimation);

scaleButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.sc));

<?xml
version="1.0"encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%" xml文件中相对比例用百分比
android:pivotY="50%"
android:toXScale="1.5"
android:toYScale="2">
</scale>

TranslateAnimation 平移

TranslateAnimationtranslateAnimation = new TranslateAnimation(30,
200, 50, 100);//
移动x从30到200,
移动y方向从50到100,
都是相对像素
translateAnimation.setDuration(1000);
transButton.startAnimation(translateAnimation);

transButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.tr));

<?xml
version="1.0"encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="30"
android:fromYDelta="50"
android:toXDelta="200"
android:toYDelta="100">
</translate>

多个Animation组合

AnimationSet animationSet=new AnimationSet(true);
animationSet.addAnimation(rotateAnimation);
rotateButton.startAnimation(animationSet);

动画监听

rotateAnimation.setAnimationListener(new AnimationListener() {

@Override
public
void
onAnimationStart(Animation arg0) {

}

@Override
public
void
onAnimationRepeat(Animation arg0) {

}

@Override
public
void
onAnimationEnd(Animation arg0) {

}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: