我有一个默认加载 Fragment StatsDetailFragment 的活动。
按下按钮后,我将使用以下代码将片段替换为另一个片段。
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
任何帮助将不胜感激。