Replace the fragment, and then press back quickly because the user interface response delay, shadows and corners disappear

I had a very strange problem. My situation:

I created an application containing many pages, each page is a Fragment . And I used RecyclerView and CardView inside each page. The layout of the main page is as follows:

enter image description here

When I click an image element to go to the detail page, then click the back button right after that, my home page will appear, but:

enter image description here

As you can see, all the shadow and corner effect disappeared , scrolling did not work when I touch an element that takes a few seconds before moving around the detailed page . When a detailed page is displayed, everything returns to normal. Here is my fragment replacement method:

 public void replaceBackgroundFragment(Fragment mf, String tag, boolean addBackStack) { if (mf != null && (currentFragmentTag == null || !currentFragmentTag.equals(tag))) { FragmentTransaction ft = fragmentManager.beginTransaction(); ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right); ft.replace(R.id.rl_background, mf, tag); if (addBackStack) { mf.setCanBack(true); ft.addToBackStack(tag); } ft.commit(); pendingFragment = null; pendingTag = null; } } 

When you click on an item:

 public void onItemClick(MainBanner item) { MoviePlayerFragment fragment = MoviePlayerFragment.newInstance(item.getItemID()); activity.replaceBackgroundFragment(fragment, "movie_player_fragment" + item.getItemID(), true); } 

EDIT I used setRetainInstance(true); in my Fragment

Can anyone tell me what is going on?

+4
source share
1 answer

you can use ft.add (R.id.rl_background, mf, tag); instead of ft.replace (R.id.rl_background, mf, tag);

0
source

All Articles