DrawerLayout中的片段未显示

时间:2017-05-04 15:32:55

标签: android android-fragments drawerlayout

我想在drawerlayout视图中显示一个片段。我有这样的活动布局:

    <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/filter_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_happay"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:elevation="8dp"
                android:gravity="center"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs_dashboard"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                app:tabIndicatorColor="@color/accent"
                app:tabMode="fixed" />

        </android.support.design.widget.AppBarLayout>


        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </android.support.design.widget.CoordinatorLayout>

    <FrameLayout
        android:id="@+id/rl_filter_frag_place_holder"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:clickable="true" />

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

我想在单击菜单项时显示抽屉。我在运行时向框架布局添加了一个片段,如下所示:

FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.add(rlFilterView.getId(), FilterFragment.newInstance(currentFrag.getContentType(), "activity",this)).commit();

问题是片段没有显示但我可以在菜单点击上看到抽屉布局的半透明叠加。这个代码适用于其他布局。需要帮助!

0 个答案:

没有答案