Lag al reemplazar el fragmento ViewPager en la barra de navegación sobre FrameLayout?

Estoy utilizando https://github.com/mikepenz/MaterialDrawer como una biblioteca para el cajón, y estoy usando https://github.com/florent37/MaterialViewPager para View Pager.

El problema que me enfrenta es que me enfrento a un poco de retraso (tipo de retraso de tartamudeo) cuando hago clic en el elemento de lista en mi cajón y el cierre de la drwawer, después de lo cual el fragmento se sustituye más. Me enfrento a esto en un fragmento que es un ViewPager es un fragmento.

Ver la imagen

Activity(which has NavBar): public class mvpAct extends AppCompatActivity { private RelativeLayout mRelativeLayout; public static List<Model_Slots> list; private Drawer result; private static GetDetails gd; public static List<Model_Daywise> todayslist_m; public static List<Model_Daywise> todayslist_t; public static List<Model_Daywise> todayslist_w; public static List<Model_Daywise> todayslist_th; public static List<Model_Daywise> todayslist_fr; public static List<detailattlist_subcode> detail_att_all = new ArrayList<>(); public static HashMap<String, List<DetailAtten>> hash = new HashMap<>(); public static List<AttendBrief> attendBriefs = null; public static List<Marks_Model> marks_det; public static List<PBL_Model> lpbl; public void setMTWTFLists(final Context ctxt) { String mark = new SharedPrefs(ctxt).getMsg("marksdone").trim(); String att = new SharedPrefs(ctxt).getMsg("ttdone").trim(); String tt = new SharedPrefs(ctxt).getMsg("attendone").trim(); Log.d("Done Value", mark + "\t" + att + "\t" + tt); if (mark.equals("y") && att.equals("y") && tt.equals("y")) { Log.d("Here", "naive"); try { new Thread(new Runnable() { public void run() { todayslist_m = new MTWTHgetset(ctxt, "monday").getAllCredentials(); todayslist_t = new MTWTHgetset(ctxt, "tuesday").getAllCredentials(); todayslist_w = new MTWTHgetset(ctxt, "wednesday").getAllCredentials(); todayslist_th = new MTWTHgetset(ctxt, "thursday").getAllCredentials(); todayslist_fr = new MTWTHgetset(ctxt, "friday").getAllCredentials(); } }).start(); } catch (Exception e) { e.printStackTrace(); } } } @Override public void onBackPressed() { if (gd.isAdded()) getSupportFragmentManager() .beginTransaction().remove(gd).commit(); else super.onBackPressed(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drawer_frame_mvp); gd = new GetDetails(); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction().add(R.id.mvp_frame_act, gd).commit(); } try { list = new Slots_GetSet(this).getAllCredentials(); String classnbrs[] = new String[list.size()]; int r = 0; for (Model_Slots ms : list) { classnbrs[r++] = ms.getNumber().trim(); } for (int t = 0; t < classnbrs.length; t++) { detailattlist_subcode dr = new detailattlist_subcode(); hash.put(classnbrs[t], new IndivAttGetSet(this, " table_of_" + classnbrs[t]).getAllCredentials()); } } catch (Exception e) { e.printStackTrace(); } try { attendBriefs = new Attend_GetSet(this).getAllCredentials(); } catch (Exception e) { e.printStackTrace(); } try { marks_det = new CBL_Get_Set(this).getAllCredentials(); } catch (Exception e) { e.printStackTrace(); } try { lpbl = new PBL_Get_Set(this).getAllCredentials(); } catch (Exception e) { e.printStackTrace(); lpbl = new ArrayList<>(); } try { setMTWTFLists(getApplication()); } catch (Exception e) { e.printStackTrace(); } PrimaryDrawerItem item1 = new PrimaryDrawerItem().withName("Slots").withIdentifier(1); SecondaryDrawerItem item2 = new SecondaryDrawerItem().withName("ImageStudentLogin").withIdentifier(2); result = new DrawerBuilder() .withActivity(this) .addDrawerItems( item1, new DividerDrawerItem(), item2, new SecondaryDrawerItem().withName("Setup"), new SecondaryDrawerItem().withName("Daywise") ) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { displayView(position); if (result.isDrawerOpen()) result.closeDrawer(); return true; } }) .build(); } private void displayView(int position) { Fragment fragment = null; switch (position) { case 0: String s = getSharedPreferences("sp", Context.MODE_PRIVATE).getString("own", "no"); if (s.equals("already")) { fragment = new Fragment_slots(); } else if (s.equals("yes")) { list = new Slots_GetSet(getApplicationContext()).getAllCredentials(); fragment = new Fragment_slots(); } else if (s.equals("no")) { fragment = new GetDetails(); } break; case 2: fragment = new Photo_Stu(); break; case 3: fragment = new GetDetails(); break; case 4: fragment = MaterialVPFrag.newInstance(); break; default: fragment = MaterialVPFrag.newInstance(); break; } if (fragment != null) { FragmentManager fm = getSupportFragmentManager(); fm.beginTransaction().replace(R.id.mvp_frame_act, fragment).commit(); } else { Log.e("DrawerActivity", "Error creating fragment"); } } } 

Fragmento (donde me enfrento al retraso (tipo de retraso del tartamudeo) en proceso de cierre del cajón, Después de lo cual se sustituye por otro bastidor):

 public class MaterialVPFrag extends Fragment { private MaterialViewPager mViewPager; public static MaterialVPFrag newInstance() { return new MaterialVPFrag(); } @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.mvp_layout, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { mViewPager = (MaterialViewPager) view.findViewById(R.id.materialViewPager); mViewPager.getViewPager().setAdapter(new FragmentStatePagerAdapter(getChildFragmentManager()) { @Override public Fragment getItem(int position) { switch (position) { case 0: return new RecyclerViewFragment(mvpAct.todayslist_m); case 1: return new RecyclerViewFragment(mvpAct.todayslist_t); case 2: return new RecyclerViewFragment(mvpAct.todayslist_w); case 3: return new RecyclerViewFragment(mvpAct.todayslist_th); case 4: return new RecyclerViewFragment(mvpAct.todayslist_fr); default: return new RecyclerViewFragment(mvpAct.todayslist_m); } } @Override public int getCount() { return 5; } @Override public CharSequence getPageTitle(int position) { switch (position) { case 0: return "Monday"; case 1: return "Tuesday"; case 2: return "Wednesday"; case 3: return "Thursday"; case 4: return "Friday"; } return ""; } }); mViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() { @Override public HeaderDesign getHeaderDesign(int page) { switch (page) { case 0: return HeaderDesign.fromColorAndDrawable(getResources().getColor(R.color.colorPrimary), getResources().getDrawable(R.drawable.myback)); case 1: return HeaderDesign.fromColorResAndUrl( R.color.blue, "http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg"); case 2: return HeaderDesign.fromColorResAndUrl( R.color.cyan, "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg"); case 3: return HeaderDesign.fromColorResAndUrl( R.color.red, "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg"); } return null; } }); mViewPager.getViewPager().setOffscreenPageLimit(mViewPager.getViewPager().getAdapter().getCount()); //it works without it don't know why! mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager()); mViewPager.getPagerTitleStrip().setBackgroundColor(Color.TRANSPARENT); mViewPager.getPagerTitleStrip().setIndicatorColor(Color.RED); mViewPager.getPagerTitleStrip().setTabBackground(Color.TRANSPARENT); View logo = view.findViewById(R.id.logo_white); if (logo != null) logo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mViewPager.notifyHeaderChanged(); } }); } } 

Fragmento interno de ViewPager:

 public class RecyclerViewFragment extends Fragment { private RecyclerView mRecyclerView; public static RecyclerView.Adapter mAdapter; List<Model_Daywise> list; public RecyclerViewFragment() { } public RecyclerViewFragment(List<Model_Daywise> lis) { list = lis; } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_recyclerview, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(layoutManager); mAdapter = new RecyclerViewMaterialAdapter(new CardAdapter_Daywise(list, getActivity())); mRecyclerView.setAdapter(mAdapter); MaterialViewPagerHelper.registerRecyclerView(getActivity(), mRecyclerView, null); } } 

¡Gracias!

    La última versión del MaterialDrawer viene con un retardo incorporado de 50ms después de encender el evento del oyente antes de cerrar el cajón sí mismo.

    Si tiene un comportamiento más complejo al cambiar fragmentos, tiene sentido modificar este retardo y cambiarlo a 150 ms o incluso 250 ms.

    Esto puede hacerse a través del método constructor

     withDelayOnDrawerClose(int delay) 

    Si desea que el cajón se cierre instantáneamente y después cambie los fragmentos, debe ajustar el retardo a 0ms y agregar un controlador dentro de su elemento de cajón.

     new Handler().postDelayed(new Runnable() { @Override public void run() { //your logic in here } }, yourDelay); 
    FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.