我有一个Navigation Drawer
,可以在两个片段和两个正常活动之间进行选择。抽屉中还有一个带有ImageView
和TextView
的标题(但我认为这不是问题,因为即使没有mipmap,它也会滞后)。
事实是,在任何情况下(打开和关闭),它在滑动时都会滞后。哪里出问题了?我在此处检查了StackOverflow上的其他问题,这是我得到的,没有结果。
在主要活动的onCreate
中:
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolb, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
Log.v("bbbb","Drawer closed");
if(frgmOrNot) {
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, mFragmentToSet, "MAIN_FRAG").commit();
mFragmentToSet = null;
frgmOrNot=false;
}
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
f = (MainFragment)getSupportFragmentManager().findFragmentByTag("MAIN_FRAG");
if(f.getActionMode())
f.getAct().finish();
}
};
mDrawerToggle.syncState();
mDrawerLayout.addDrawerListener(mDrawerToggle);
所选项目:
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()){
case R.id.nav_available:
frgmOrNot = true;
mFragmentToSet = MainFragment.newInstance(0);
break;
case R.id.nav_download:
frgmOrNot = true;
mFragmentToSet = MainFragment.newInstance(1);
break;
case R.id.nav_upload:
frgmOrNot = false;
Intent j = new Intent(this,UploadActivity.class);
startActivity(j);
break;
case R.id.nav_about:
frgmOrNot = false;
Intent i = new Intent(this,AboutActivity.class);
startActivity(i);
break;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
if(frgmOrNot)
return true; //just to show the correct item selection
else
return false;
}