I suspect that its happening because of transition name is not set but im unable to detect that is it the reason or there is another reason or what I'm doing wrong or what is missing, here is my code:
on click of recyclerview item: i didn't set transition name in on bind view if i do it also don't work
holder.iv.setTransitionName(MainActivity.position + "ZoomImage");
MainActivity.position = position;
ImagePagerFragment productDetailFragment = new ImagePagerFragment();
productDetailFragment.setEnterTransition(R.transition.image_shared_element_transition);
productDetailFragment.postponeEnterTransition();
getActive.getSupportFragmentManager()
.beginTransaction()
.setReorderingAllowed(true)
.addSharedElement(holder.iv, holder.iv.getTransitionName())
.replace(R.id.fragment, productDetailFragment)
.addToBackStack(null)
.commit();
in ImagePagerFragment:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
prepareSharedElementTransition();
postponeEnterTransition();
}
prepareSharedElementTransition();:
Transition transition =
TransitionInflater.from(getContext())
.inflateTransition(R.transition.image_shared_element_transition);
setSharedElementEnterTransition(transition);
setEnterTransition(transition);
setEnterSharedElementCallback(
new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
Fragment currentFragment = (Fragment) viewPager.getAdapter()
.instantiateItem(viewPager, viewPager.getCurrentItem());
View view = currentFragment.getView();
if (view == null) {
return;
}
sharedElements.put(names.get(0), view.findViewById(R.id.image1));
}
});
adapter on viewpager simply returning a fragment, ImageFragment, in ImageFragment in picasso success callback:
ivZoom.setTransitionName(MainActivity.position + "ZoomImage");
getParentFragment().startPostponedEnterTransition();
for exit ImageFragment i have button on button click:
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getParentFragment().getFragmentManager().popBackStack();
ivZoom.getTransitionName();
}
}, 500);
}
});
and on exit transition is not working
onBind of recyclerview adapter:
Picasso.with(context)
.load(imageArrayList.get(position).getUrl())
// .networkPolicy(NetworkPolicy.OFFLINE)
.placeholder(R.drawable.loading_tall)
.fit().centerCrop()
.into(holder.iv, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// holder.iv.setTransitionName(MainActivity.position + "ZoomImage");
}
}
@Override
public void onError() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// holder.iv.setTransitionName(MainActivity.position + "ZoomImage");
}
}
});