Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Shared element transition from a fragment to an activity

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

I have searched each every places internet but there are info only about shared element transition from one fragment to another and one activity to another. There is no content about transition 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());

On using the above code the second activity is launched but nothing is visible, For example the second activity contains a FAB which when clicked youtube is launched. I know where the FAB is so when i click blindly, youtube launched correctly but nothing is visible in second activity

D/ViewRootImpl: changeCanvasOpacity: opaque=true

Its one of the logcats. I think this must be the problem!!

like image 426
user3740778 Avatar asked Jul 26 '16 15:07

user3740778


People also ask

Which of the following transitions is a shared elements transition?

Android also supports these shared elements transitions: changeBounds - Animates the changes in layout bounds of target views. changeClipBounds - Animates the changes in clip bounds of target views. changeTransform - Animates the changes in scale and rotation of target views.

Can we move from fragment to activity in Android?

Can I go from fragment to activity Android? You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your activity.

What is Fragment transition?

The Fragment API provides two ways to use motion effects and transformations to visually connect fragments during navigation. One of these is the Animation Framework, which uses both Animation and Animator . The other is the Transition Framework, which includes shared element transitions.

Can fragments be used in multiple activities?

Yeah you can use same fragment in different activities. Create a fragment_container view in all activities that you need to call the fragment. Then call the fragment into that container .


1 Answers

I had the same problem, I couldn't find anything that helps sorry, but maybe you should reconsider why would you need a Fragment to Activity relation when you could work with a Fragment to Fragment or Activity to Activity relation.

I've solved my problem that way changing my code to a Fragment to Fragment relation and there is plenty documentation and examples about that Shared Element Transitions

like image 95
Carlos Avatar answered Sep 19 '22 18:09

Carlos