2

我在两个片段之间使用 SharedElement 转换。.replace() 可以正常工作,但是如果我使用 .add(),则转换不起作用。我错过了什么吗?

onItemClickListener 启动新片段。

urlSetter(list.get(position).getId());
TextView image = (TextView) itemView.findViewById(R.id.teamID);

newFragment = new TeamsActivity();
Bundle args = new Bundle();

FragmentTransaction transaction = getFragmentManager().beginTransaction();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    args.putString("TRNS", image.getTransitionName());
    newFragment.setSharedElementEnterTransition(TransitionInflater.from(getActivity()).inflateTransition(R.transition.trans_move));
    newFragment.setEnterTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.explode));
    setSharedElementReturnTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.slide_top));
    setExitTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.no_transition));
    transaction.addSharedElement(image, image.getTransitionName());
}
args.putInt("LOGO", mTeamLogos[list.get(position).getId()].getDrawableId());
args.putString("CLUB", list.get(position).getName2());
args.putString("URL", url);
args.putInt("POSITION", position);
newFragment.setArguments(args);

transaction.addToBackStack("xyz");
transaction.add(R.id.frame_layout, newFragment);
transaction.commit();
4

0 回答 0