androidlistviewshared-element-transition

Shared content transition to header view (Android)


I have the following problem:

I have defined a shared element transition between two activities. In the first activity, i start the second activity with the following code:

ActivityOptionsCompat options =ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view.findViewById(R.id.user_picture), transitionName);
ActivityCompat.startActivity(getActivity(), i, options.toBundle());

And in the second activity, i have a view with an android:transitionName which is the same as the transitionName variable, and it works, if this view is in the xml file that is set as activity content. But, when this view is inflated as part of a header of a list in the onCreate of the second activity:

mListView = (ExpandableListView) findViewById(R.id.user_details_list);
//inflate the header
mHeader = getLayoutInflater().inflate(R.layout.header_user_details, mListView, false);
mListView.addHeaderView(mHeader);

the enter transition doesn't seem to find the view with the same transitionName, and doesn't work. But, the exist transition does seem to find this view and it displays ok. Is there any way to inflate the header so the enter transition can find the shared element?


Solution

  • Ok, i have solved it. Simply use an sharedElementCallback on the second activity, and on the onMapSharedElements method, manually find your view and map it to the proper transitionName.