我有一个Recyclerview在网格中显示一些图像。当我单击其中一个图像时,我添加了一个新图像,其中图像作为共享元素。我还使用爆炸过渡来将recyclelerview中的其他项目移出屏幕。当我添加片段时,过渡运行正常,图像缩放到全屏。当我弹出后面的堆栈时,动画不会反向运行,因为我会这样做。共享元素从屏幕上的错误位置缩放和转换。如果我使用另一个转换,如淡入淡出,我没有任何问题。
这是我添加细节片段的网格片段。
public class GridFragment extends Fragment implements ItemAdapter.BobbleClickListener {
@Bind(R.id.image_recycler_view)
RecyclerView mImageRecycler;
public static GridFragment newInstance(int imageArrayResource, int titlesArrayResource) {
GridFragment fragment = new GridFragment();
Bundle args = new Bundle();
args.putInt("KEY_IMAGES", imageArrayResource);
args.putInt("KEY_TITLES", titlesArrayResource);
fragment.setArguments(args);
return fragment;
}
public GridFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_grid, container, false);
ButterKnife.bind(this, root);
Bundle args = getArguments();
int imageArrayResource = args.getInt("KEY_IMAGES");
int titlesArrayResource = args.getInt("KEY_TITLES");
ItemAdapter mainAdapter = new ItemAdapter(getActivity(), this, imageArrayResource, titlesArrayResource);
mImageRecycler.setHasFixedSize(true);
mImageRecycler.setLayoutManager(new GridLayoutManager(getActivity(), 4));
mImageRecycler.setAdapter(mainAdapter);
return root;
}
@Override
public void onBobbleClick(ImageView imageView, int resource) {
setExitTransition(new Explode());
DetailFragment detailFragment = DetailFragment.newInstance(resource, imageView.getTransitionName());
detailFragment.setSharedElementEnterTransition(TransitionInflater.from(getActivity()).inflateTransition(R.anim.trans_move));
FragmentTransaction trans = getActivity().getSupportFragmentManager().beginTransaction();
trans.replace(R.id.content, detailFragment);
trans.addSharedElement(imageView, imageView.getTransitionName());
trans.addToBackStack(null);
trans.commit();
}
}
这是详细信息片段
public class DetailFragment extends Fragment {
@Bind(R.id.detail_iv)
ImageView mImageView;
public static DetailFragment newInstance(int imageResource, String transitionName){
DetailFragment fragment = new DetailFragment();
Bundle args = new Bundle();
args.putInt("RESOURCE_KEY", imageResource);
args.putString("RESOURCE_TRANSITION_NAME", transitionName);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_detail, container, false);
ButterKnife.bind(this, root);
mImageView.setTransitionName(getArguments().getString("RESOURCE_TRANSITION_NAME"));
mImageView.setImageResource(getArguments().getInt("RESOURCE_KEY"));
return root;
}
}
这是我的共享元素转换集trans_move
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds/>
<changeTransform/>
<changeClipBounds/>
<changeImageTransform/>
</transitionSet>
这是下面的问题