I have recyclerview on click of its item i'm opening an activity with shared element transition like this:
Intent myIntent = new Intent(getActive, EnlargeActivity.class);
myIntent.putExtra("IMAGE_URL", imageArrayList.get(position).getUrl());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
holder.iv.setTransitionName(String.valueOf(MainActivity.position + "ZoomImage"));
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(getActive,
holder.iv,
ViewCompat.getTransitionName(holder.iv));
context.startActivity(myIntent, options.toBundle());
in activity it has viewpager:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enlarge);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setEnterTransition(null);
}
supportPostponeEnterTransition();
In viewpager adapter which extends FragmentStatePagerAdapter returning a fragment ProductDetailViewPagerFragment that has an imageview and im loading images like this: (MainActivity.position is position of recyclerview)
Picasso.with(getActivity())
.load(url)
.into(imageView, new Callback() {
@Override
public void onSuccess() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
imageView.setTransitionName(MainActivity.position + "ImageZoom");
}
getActivity().supportStartPostponedEnterTransition();
}
@Override
public void onError() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
imageView.setTransitionName(MainActivity.position + "ImageZoom");
}
getActivity().supportStartPostponedEnterTransition();
}
});
I think you should setTransitionName for ViewPager in the second activity. The previous view will be connected with viewPager. If you call
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
imageView.setTransitionName(MainActivity.position + "ImageZoom");
}
after image load success (or failed), the transition is finished and it will be not working.