具有动画的LocalActivityManager destroyActivity

时间:2012-03-07 13:22:37

标签: android animation back activitygroup

我想在活动回调方法时添加动画效果。我使用activityGroup来实现activitymanger并使用LocalActivityManager来启动和支持任何活动。

开始活动时添加动画使用以下代码

public static void startActivity(Intent intent, String id) {

    View view = mLocalActivityManager.startActivity(id,
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();

    Animation hyperspaceJump = AnimationUtils.loadAnimation(mActivityGroup,
            R.anim.dync_in_from_right);
    view.startAnimation(hyperspaceJump);

    view.setTag(id);
    mPreviousActivityTag = getCurrentActivityTag();
    mViewContainer.addView(view);
}

但我不知道如何在活动返回到启动cur活动的活动时添加动画效果。后面的方法就像那样

public static void removeCurrentActivity() {

    String tag = getCurrentActivityTag();
    if (com.ct.ipaipai.global.Utily.isStringEmpty(tag) == false) {

        int cnt = getActivityCount();
        mViewContainer.removeViewAt(cnt - 1);
        View view = mLocalActivityManager.destroyActivity(tag, true).getDecorView();
    }
}

任何人都知道吗?

感谢

1 个答案:

答案 0 :(得分:2)

我不知道您使用的是哪个ActivityGroup,但有时在过去使用ActivityGroup时,我做了类似的事情

String tag = getCurrentActivityTag();
LocalActivityManager manager = getLocalActivityManager();
Animation animation = null;
animation = AnimationUtils.loadAnimation(this, R.anim.de_rail);
Window oldWindow = manager.getCurrentActivity().getWindow();
if(oldWindow != null)
{
    View v =oldWindow.getDecorView();
    v.setBackgroundResource(R.drawable.app_pink_background);
    v.startAnimation(animation);                
}
manager.destroyActivity(tag, true);
// now set old Activity View
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
if(newWindow != null)
{
    View view = newWindow.getDecorView();
    setContentView(view);           
}

其中R.anim.de_rail,其实是de_rail.xml就像这样:

<?xml version="1.0" encoding="utf-8"?>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0%p"
    android:toXDelta="100%p"
    android:duration="400" />

您可以找到my modified version here。它会在启动子Activity和完成孩子Activity上显示动画。