As a transition from a common fragment to a fragment to activity

I have three fragments inside the ViewPager in activity, I want to achieve the transition of a common element from one of the fragments to another. The transition is carried out from the view of the recycler, which is located inside the fragment, which is located inside the viewpager, which is located inside Activity Activity-> ViewPager-> Fragment-> Recyclerview

I searched every website, but there is information only about the transition of a common element from one fragment to another and one action to another. There is no content about moving from fragment to activity

holder.poster.setTransitionName("posterX"); ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) con,holder.poster,holder.poster.getTransitionName()); Log.e("Animation", "Success"); //startActivity((Activity) con,intent,options.toBundle()); c.startActivity(intent,options.toBundle()); 

When using the above code, the second action is launched, but nothing is visible, for example, the second action contains FAB, which starts when you click on the youtube button. I know where the FAB is, so when I click blindly, youtube is launched correctly, but nothing is visible in the second activity.

 D/ViewRootImpl: changeCanvasOpacity: opaque=true 

Its one of the logarithms. I think this should be a problem!

+10
source share
4 answers

I had the same problem, I could not find anything that could help, but maybe you should reconsider why you need a Fragment to Activity relation when you can work with a Fragment to Fragment or Activity to Activity relation.

I solved my problem this way, changing my code to fragment to fragment relation, and there is a lot of documentation and examples on what Transitions with a common element

+1
source

A fragment for an Activity is the same as an Activity to Activity, because your fragment is inside an Activity.

+1
source

I finally found the answer, the startActivity call method is different. You have to call

 startActivityFromFragment(fragment, intent, req_code, options.toBundle()); 

from AppCompactActivity

+1
source

I think using pairs as below:

  Pair[] pairs = new Pair[1]; pairs[0] = new Pair<View, String>(tvArtifacts, "itemTrans"); ActivityOptions options = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { options = ActivityOptions.makeSceneTransitionAnimation(getActivity(), pairs); } Intent i = new Intent(getActivity(), ItemDetailActivity.class); i.putExtra("item_name", "item 2"); if (options != null) { startActivity(i, options.toBundle()); } else { startActivity(i); } 

It worked for me! Thanks..

0
source

All Articles