I have an ActivityA containing FragmentA, and would like to make a transition of a common element in ActivityB containing FragmentB.
In actions, the toolbar will be a common element. In fragments, it will be text. Is there any way to do this?
If not, how can I make a general transition of an element between both fragments in actions?
Thanks in advance for any help. I am stuck.
Ok, so I will provide some code for clarification.
Here I have MainActivity:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" android:transitionName="sharedToolbar"/> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/activity_main_container" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.design.widget.CoordinatorLayout>
This operation contains this fragment called MainFragment:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Fragment main" android:transitionName="sharedFragment"/> <Button android:id="@+id/fragment_main_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Go to detail screen" android:layout_gravity="bottom|center"/> </FrameLayout>
Now what I want to do is when I click the button in MainFragment. I want to execute a fragment transaction for this action called DetailActivity:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" android:transitionName="sharedToolbar"/> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/activity_detail_container" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.design.widget.CoordinatorLayout>
This operation contains this fragment called DetailFragment:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Fragment detail" android:transitionName="sharedFragment"/> </FrameLayout>
As you can see in the code, both actions share a toolbar and have the same transition name. In their containing fragments there is a text that I would like to animate also at the transition. These text images also have the same transition name. Is there any way to do this? I tried, and so far I could only animate the toolbar between these two actions. How to make fragments perform a joint transition of an element at the same time?
If this is not possible, how can I do this when I move from MainActivity to DetailActivity, that the textual representation of the fragments is what appears as a transition, not a toolbar (if I cannot activate the activity of fragmentation and at the same time).