I am trying to create transition from single RecyclerView
            item to new DetailsFragment.
This is my
            situation:
Layout
            hierarchy:
 (Lvl1) MainActivity
            (fragment_container)
 (Lvl2) HomeFragment
 (Lvl3)
            ViewPager
 (Lvl4) AnotherFragment
 (Lvl5) RecyclerView
            (Lvl6) CardView (transitionName="item")
 (Lvl2) DetailsFragment
            (Lvl3) RelativeLayout
            (transitionName="item")
So,
            when item inside RecyclerView is clicked, fragmentTransaction will replace HomeFragment
            with DetailsFragment and what i want to achieve is "changeBounds" from CardView to
            RelativeLayout while HomeFragment is fadingOut and DetailsFragment in
            fadingIn.
My solution can be seen below and
            problem that i have is that DetailsFragment is instantly shown in background on
            transaction commit. Clicked CardView remains visible (above DetailsFragment) and it is
            fading as it should, but without any changes in dimension or position. All other
            CardViews are invisible during this
            operation.
It is obvious that i do not
            undesrstand something here and it is not working as it
            should...
activity_main.xml
            android:id="@+id/fragmentContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
MainActivity.java
            ->
            OnRecyclerViewItemClick
@Override
public
            void onRecyclerViewClick(int position, int key) {
 if (Build.VERSION.SDK_INT
            >= Build.VERSION_CODES.LOLLIPOP) {
 Fade fadeOutTransition = new
            Fade(Fade.OUT);
 fadeOutTransition.setDuration(2000);
 Fade
            fadeInTransition = new Fade(Fade.IN);
            fadeInTransition.setStartDelay(2000);
            fadeInTransition.setDuration(10000);
 ChangeBounds
            changeBoundsTransition = new ChangeBounds();
            changeBoundsTransition.setDuration(10000);
            homeFragment.setSharedElementEnterTransition(changeBoundsTransition);
            homeFragment.setReenterTransition(fadeInTransition);
            homeFragment.setExitTransition(fadeOutTransition);
            frag.setEnterTransition(fadeInTransition);
            frag.setAllowEnterTransitionOverlap(false);
            frag.setAllowReturnTransitionOverlap(false);
            frag.setSharedElementEnterTransition(changeBoundsTransition); 
            ViewPager pager =
            (ViewPager)((FrameLayout)homeFragment.getView()).getChildAt(0);
            RelativeLayout pagerLayout = (RelativeLayout) pager.getChildAt(0);
            RecyclerView recycler = (RecyclerView)pagerLayout.getChildAt(0);
            View view = recycler.getChildAt(position); 
            getSupportFragmentManager().beginTransaction()
            .replace(R.id.fragmentContainer, frag)
 .addToBackStack(null)
            .addSharedElement(view , "item")
            .commit();
 
No comments:
Post a Comment