在另一个布局中扩展布局

时间:2018-04-02 05:29:42

标签: android android-layout navigation-drawer

我正在开发导航抽屉布局。另一个布局必须加载代替 drawer_layout onClick导航项。

NEW_DATABASE.NEW_SCHEMA

如何在mainlayout中加载另一个布局。?

1 个答案:

答案 0 :(得分:1)

你必须创建片段 (右键点击您的项目 - >新建 - >片段)。然后在此下方的Activity中加载..

 if (id == R.id.nav_camera) {

     CameraFragment camera = new CameraFragment();
     FragmentManager fragmentManager = getFragmentManager();
     FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();              
     fragmentTransaction.add(R.id.fragment_container, camera, "HELLO");
     fragmentTransaction.commit();


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

     GalleryFragment gallery = new GalleryFragment();
     FragmentManager fragmentManager = getFragmentManager();
     FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();              
     fragmentTransaction.add(R.id.fragment_container, gallery, "HELLO");
     fragmentTransaction.commit();

    }