sometime,we can not avoid a view disappearing,for example: nested fragment will be disappeared when the parent fragment is removed/replaced,
in order to avoid the user seeing the nested fragment disappearing,you could simulate those fragments still being present by providing an image of them,
as they appeared on the screen. this image will be used as a background for the nested fragments containerso even if the views of the nested fragment go away the image will simulate their presence.
the following code was a little example with setting up the background image
public static class FragmentA extends Fragment {private Bitmap b = null ;@Overridepublic void onCreate ( Bundle savedInstanceState ) {super . onCreate ( savedInstanceState );getChildFragmentManager (). beginTransaction (). add ( android . R . id . list , new FragmentA1 ()). add ( android . R . id . list , new FragmentA2 ()). commit ();}@Overridepublic View onCreateView ( LayoutInflater inflater , ViewGroup container ,Bundle savedInstanceState ) {LinearLayout layout = new LinearLayout ( container . getContext ());layout . setBackgroundColor ( Color . RED );layout . setOrientation ( LinearLayout . VERTICAL );layout . setId ( android . R . id . list );return layout ;}@Overridepublic void onPause () {b = loadBitmapFromView ( getView ());super . onPause ();}public static Bitmap loadBitmapFromView ( View v ) {Bitmap b = Bitmap . createBitmap ( v . getWidth (),v . getHeight (), Bitmap . Config . ARGB_8888 );Canvas c = new Canvas ( b );v . layout ( 0 , 0 , v . getWidth (), v . getHeight ());v . draw ( c );return b ;}@Overridepublic void onDestroyView () {BitmapDrawable bd = new BitmapDrawable ( b );getView (). findViewById ( android . R . id . list ). setBackground ( bd );b = null ;super . onDestroyView ();}}