android - 添加片段时不显示抽屉和工具栏
问题描述
当我将片段添加到 content_frame 中时 - 我看不到抽屉(滑动无济于事)和工具栏。
当我不添加片段时,我可以看到它们。我的实施有什么问题?
MainActivity 布局:
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
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="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</LinearLayout>
<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/navigation_header"
app:menu="@menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
播放列表片段布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/playlist_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
我正在使用数据绑定(也许它很重要......)所以很明显布局文件上的第一件事是标签,它是孩子,然后是实际的布局/视图。
解决方案
您需要使用 CoordinatorLayout 才能使应用栏滚动工作。尝试使用此布局
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
<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/navigation_header"
app:menu="@menu/drawer_view" />
推荐阅读
- oracle - 在两列上没有重复的休眠查询
- python - 如何以最佳方式访问 MongoDB 中的最新数据点?
- python - Python 3 属性错误:Statsmodels 没有属性“工具”
- python - 在小程序中使用附加问题
- apache-kafka - 卡夫卡连接。将环境变量添加到自定义转换器配置
- java - 如何在 REST WebService 中实现动态 URL
- java - QueryDSL 内连接:连接的预期路径
- python-3.x - 如何从值是数据类型的熊猫数据框中制作字典?
- python - 使用 python 对 BigQuery API 运行大型查询
- laravel - laravel-5.7:数据未保存到数据库中