我有一个默认加载Fragment StatsDetailFragment的活动。
在按下按钮时,我使用以下代码替换Fragment:
getSupportFragmentManager().beginTransaction()
.replace(R.id.stats_detail_container, projectEntryListFragment, ProjectEntryListFragment.FRAGMENT_ID)
.addToBackStack(FRAGMENT_CHART)
.commit();
我正在使用自定义过渡类为ProjectEntryListFragment设置进入过渡效果。
public class RevealTransition extends Visibility {
private final Point mEpicenter;
private final int mSmallRadius;
private final int mBigRadius;
private final long mDuration;
public RevealTransition(Point epicenter, int smallRadius, int bigRadius, long duration) {
mEpicenter = epicenter;
mSmallRadius = smallRadius;
mBigRadius = bigRadius;
mDuration = duration;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
Animator animator = ViewAnimationUtils.createCircularReveal(view, mEpicenter.x, mEpicenter.y,
mSmallRadius, mBigRadius);
animator.setDuration(mDuration);
return new WrapperAnimator(animator);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
Animator animator = ViewAnimationUtils.createCircularReveal(view, mEpicenter.x, mEpicenter.y,
mBigRadius, mSmallRadius);
animator.setDuration(mDuration);
return new WrapperAnimator(animator);
}
}
过渡效果很好。但我面临的问题是,当ProjectEntryListFragment执行揭示动画时,StatsDetailFragment已经被移除了,这导致揭示动画在一个空白背景上播放。我希望它能在StatsDetailFragment上播放,这样在ProjectListFragment上播放揭示过渡时,StatsDetailFragment可见。
我尝试添加新片段,但这只会在弹出回退栈时给我一个错误。
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v4.app.Fragment.getAllowReturnTransitionOverlap()' on a null object reference
任何帮助都将不胜感激。