问题
I want to create an animation programmatically to start an activity with zoom effect from touch screen point.
With the next I simulate a zoom enter effect:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >
<scale
android:duration="@android:integer/config_mediumAnimTime"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
Right now I using the above animation starting from the center of screen (no from touch screen, which I think is better for user experience in this case).
overridePendingTransition(R.anim.zoom_enter, android.R.anim.fade_out);
I would like to know if it is possible to create an animation as:
AnimationSet animSet = new AnimationSet(false);
ScaleAnimation zoom = new ScaleAnimation(0, 0, 1, 1, 50, 50);
animSet.addAnimation(zoom);
(I'll replace the 50, 50 values to the appropriates (touch screen point)) and SET the animation to overridePendingTransition(int, int)
All info I've seen use xml transitions.
回答1:
I did it this way:
I'm created ScaleAnimation in the activity's OnCreate
method, set it's duration and started it for root view.
Animation anim = new ScaleAnimation(0, 1, 0, 1, mTouchX, mTouchY);
anim.setDuration(mAnimDuration); // duration = 300
getWindow().getDecorView().findViewById(android.R.id.content).startAnimation(anim);
It should be after setContentView
method
来源:https://stackoverflow.com/questions/22325975/how-to-create-an-activity-transition-programmatically