App>Activity>Animation
这里主要介绍补间动画应用到Activity之间的切换,这是4.0新出的动画效果
动画xml都编写在res/anim文件夹中,例如:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="@android:integer/config_longAnimTime" />
这是一个渐变动画效果。
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<scale android:fromXScale="2.0" android:toXScale="1.0"
android:fromYScale="2.0" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
这是缩放动画效果。
第一种:运行动画代码:
startActivity(new Intent(Animation.this, AlertDialogSamples.class));
overridePendingTransition(R.anim.fade, R.anim.hold);//参数一,进入动画;参数二,退出动画
这种运行代码在4.0以前也可以使用,但是下面的必须在4.0以后了。
第二种:
ActivityOptions opts = ActivityOptions.makeCustomAnimation(Animation.this, R.anim.fade, R.anim.hold);
startActivity(new Intent(Animation.this, AlertDialogSamples.class), opts.toBundle());
这两种代码运行的效果有点不同,太微小,自己可以去查看api demo的动画效果。
第三种:
在你点击view的位置打开acitivity,放大效果
private OnClickListener mScaleUpListener = new OnClickListener() {
public void onClick(View v) {
// Create a scale-up animation that originates at the button
// being pressed.
ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(
v, 0, 0, v.getWidth(), v.getHeight());
// Request the activity be started, using the custom animation options.
startActivity(new Intent(Animation.this, AlertDialogSamples.class), opts.toBundle());
}
};
第四种:
说句实话这种完全搞不懂想要干嘛,运行和第三种也差不多
private OnClickListener mZoomThumbnailListener = new OnClickListener() {
public void onClick(View v) {
v.setDrawingCacheEnabled(true);
v.setPressed(false);
v.refreshDrawableState();
Bitmap bm = v.getDrawingCache();
Canvas c = new Canvas(bm);
// c.drawARGB(255, 255, 0, 0);
ActivityOptions opts = ActivityOptions.makeThumbnailScaleUpAnimation(
v, bm, 0, 0);
// Request the activity be started, using the custom animation options.
startActivity(new Intent(Animation.this, AlertDialogSamples.class), opts.toBundle());
v.setDrawingCacheEnabled(false);
}
};
总结:第一,第二种需要创建补间动画的xml文件实现
第三种,第四种不用创建,关联的属性和你点击的view有关。