androidandroid-animationmaterial-designandroid-5.0-lollipopactivity-transition

Android exit transition excludeTarget not working inside android.support.v4.widget.DrawerLayout


I have an activity which includes a viewpager with 3 fragments. From the first tab, I am calling another activty and trying to exclude toolbar and tab bar from the exit transition.

if (Build.VERSION.SDK_INT >= 21) {

                    getActivity().getWindow().setExitTransition(new Slide(Gravity.LEFT).excludeTarget(R.id.toolbar,true));

                    Pair<View, String> pair1 = Pair.create((View) matCvr, matCvr.getTransitionName());
                    Pair<View, String> pair2 = Pair.create((View)matTxt, matTxt.getTransitionName());

                    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),pair1,pair2);
                    ActivityCompat.startActivity(getActivity(), matIntent, options.toBundle());
                }

The issue is excludeTarget seems not working and the whole view is sliding to Left. I have tried addTarget like below for including viewpager alone.But in that case, the default Fade animation is happening.

getActivity().getWindow().setExitTransition(new Slide(Gravity.LEFT).addTarget(R.id.viewPager));

Has anyone faced this issue? Any help appreciated.

Update

The issue appears when I have the views inside

android.support.v4.widget.DrawerLayout / android.support.design.widget.AppBarLayout

Solution

  • We need to make android:transitionGroup="false" explicitly for the parent views.

    True if the ViewGroup should be acted on together during an Activity transition. The default value is true when there is a non-null background or if getTransitionName() is not null or if a non-null ViewOutlineProvider other than BACKGROUND was given to setOutlineProvider(ViewOutlineProvider) and false otherwise.