Android:带有片段和活动的导航抽屉?

Android:带有片段和活动的导航抽屉?,android,android-fragments,navigation-drawer,Android,Android Fragments,Navigation Drawer,我试图用2个片段(稍后我会添加)和4个活动来完成导航抽屉。在我的代码中,当我调用activity并关闭时。它非常滞后。我希望它非常光滑。请看我的密码 ublic class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{ private DrawerLayout drawerLayout; private Toolbar tool

我试图用2个片段(稍后我会添加)和4个活动来完成导航抽屉。在我的代码中,当我调用activity并关闭时。它非常滞后。我希望它非常光滑。请看我的密码

ublic class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{

    private DrawerLayout drawerLayout;
    private Toolbar toolbar;
    private NavigationView navigationView;
    FragmentManager fragmentManager;

    private String[] pageTitle;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pageTitle = new String[]{getString(R.string.frag_home),
                getString(R.string.nav_introduction),};

        drawerLayout = (DrawerLayout)findViewById(R.id.drawerLayout);

        toolbar = (Toolbar)findViewById(R.id.toolbar);
        toolbar.setTitle(pageTitle[0]);
        setSupportActionBar(toolbar);

        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
                R.string.drawer_open, R.string.drawer_close);
        drawerLayout.addDrawerListener(toggle);
        toggle.syncState();


        navigationView = (NavigationView)findViewById(R.id.nav_view);
//        assert navigationView != null: Log.wtf("haha", "OMG");
        assert navigationView != null;
        navigationView.setNavigationItemSelectedListener(this);


        fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.frame, new Fragment_home()).commit();
    }

    @Override
    public boolean onNavigationItemSelected(MenuItem item) {

        switch(item.getItemId()) {
            case R.id.nav_introduction: {

                fragmentManager = getSupportFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.frame, new Fragment_Introduction()).commit();
            }
                break;
            case R.id.nav_settings: {
                Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                startActivity(intent);
            } break;
            case R.id.nav_feedback: {
                Intent intent = new Intent(MainActivity.this, FeedbackActivity.class);
                startActivity(intent);
            }
        }

        drawerLayout.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public void onBackPressed() {
        assert drawerLayout != null;
        if(drawerLayout.isDrawerOpen(GravityCompat.START)){
            drawerLayout.closeDrawer(GravityCompat.START);
        }
        else{
            super.onBackPressed();
        }
    }

    public void onClickHome(View view){
        fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.frame, new Fragment_home()).commit();
    }

    public void onClickFilter(View view){
        Intent intent = new Intent(MainActivity.this, FIlterActivity.class);
        startActivity(intent);
    }
}
我的主要活动代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:titleTextColor="@android:color/white" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:gravity="right">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="4">

            </LinearLayout>

            <TextView
                android:text=""
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:textColor="@android:color/white"
                android:gravity="right|center"
                android:layout_weight="1"
                android:onClick="onClickHome"/>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginRight="3dp"
                android:gravity="center"
                android:src="@drawable/filter_icon"
                android:onClick="onClickFilter"
                />


        </LinearLayout>


    </android.support.v7.widget.Toolbar>



    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/drawer_menu" />

    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

当我调用“活动”(从导航视图)并将其关闭时,您希望平滑什么。它在主活动中滞后关闭导航抽屉?
当我调用活动时
这是什么意思<代码>在主活动中是LAGY什么是LAGY?尝试在没有动画的情况下打开活动使用下面的链接:抽屉关闭时活动也应打开,因为您必须使用addDrawerListener。抽屉关闭时,应打开该活动。或者您可以使用处理程序等待一段时间,例如400毫秒,然后打开活动
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                    startActivity(intent);
                }
            }, 250);
        } break;