我正在制作动画fragment
和activity
之间的过渡动画。我遇到的问题是,当我执行从我的片段转换到新活动的调用时,SharedElement
是ImageView
,变得非常小,然后变大。当活动关闭并且元素返回其位置时,它会一直收缩到零,然后弹出到正常大小。
此视频中显示了非常类似的问题: https://www.dropbox.com/s/gzli11ae3ebz95f/2016_04_19_20_33_29.mp4?dl=0
以下是我的新活动的代码:
final ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(mActivity,
Pair.create((View) holder.sharedElement, "transition_name1"),
Pair.create((View) holder.sharedElement2, "transition_name2"));
final Intent intent = SecondActivity.startActivity(mActivity, mList.get(holder.getAdapterPosition()));
mActivity.startActivityForResult(intent, SecondActivity.REQUEST_CODE, optionsCompat.toBundle());
在我开始新的活动之后,我正在进行这种转变:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupTransitions() {
TransitionSet sharedSetEnter = new TransitionSet();
Transition bounds = new ChangeBounds();
bounds.addTarget("transition_name2");
bounds.excludeTarget(R.id.toolbar, true);
bounds.setDuration(300);
Transition arcShared = new ChangeBounds();
arcShared.addTarget("transition_name1");
arcShared.setPathMotion(new ArcMotion());
arcShared.setDuration(200);
sharedSetEnter.addTransition(arcShared);
sharedSetEnter.addTransition(bounds);
TransitionSet sharedSetExit = new TransitionSet();
sharedSetExit.addTransition(arcShared);
sharedSetExit.addTransition(bounds);
Transition fade = new Fade();
fade.setDuration(100);
fade.excludeTarget(android.R.id.statusBarBackground, true);
fade.excludeTarget(android.R.id.navigationBarBackground, true);
sharedSetEnter.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
initLayouts();
}
@Override
public void onTransitionEnd(Transition transition) {}
@Override
public void onTransitionCancel(Transition transition) {}
@Override
public void onTransitionPause(Transition transition) {}
@Override
public void onTransitionResume(Transition transition) {}
});
sharedSetExit.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
setUnnecessaryLayoutsInvisible();
}
@Override
public void onTransitionEnd(Transition transition) {
}
@Override
public void onTransitionCancel(Transition transition) {}
@Override
public void onTransitionPause(Transition transition) {}
@Override
public void onTransitionResume(Transition transition) {}
});
getWindow().setSharedElementEnterTransition(sharedSetEnter);
getWindow().setSharedElementReturnTransition(sharedSetExit);
getWindow().setEnterTransition(fade);
getWindow().setReturnTransition(fade);
}
因此动画被称为ok,但ImageView除外,它不能按比例缩放。大小从0-1到1-0而不是像0.4-1和1-0.4
非常感谢任何帮助。