导航抽屉:碎片重叠

时间:2016-12-24 14:34:12

标签: java android android-fragments android-navigation-drawer

我正在创建一个简单的导航抽屉。当我在不同标签之间切换时,片段的内容与主要活动的内容重叠

这是主要活动的代码

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {
        CamFragment camFragment = new CamFragment();
        FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction().replace(R.id.content_main, camFragment).commit();

    } else if (id == R.id.nav_gallery) {

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

我的CamFragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_cam, container, false);
}

应用的ScreenShot

enter image description here

0 个答案:

没有答案