How to create an activity transition programmatically ?

狂风中的少年 提交于 2019-12-25 04:28:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!