我怀疑由于转换名称而发生的事情未设置但是我无法检测到它是原因还是有其他原因或我做错了什么或者缺少什么,这是我的代码:< / p>
点击recyclerview项目:我没有在绑定视图中设置转换名称,如果我这样做也不能工作
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();
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));
}
});
viewpager上的适配器只是在picasso成功回调中的ImageFragment中返回一个片段ImageFragment:
ivZoom.setTransitionName(MainActivity.position + "ZoomImage");
getParentFragment().startPostponedEnterTransition();
退出ImageFragment我点击按钮上的按钮:
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);
}
});
并且退出转换无法正常工作
recyclelerview适配器的onBind:
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");
}
}
});