【发布时间】:2019-03-22 00:44:16
【问题描述】:
我是 android 新手,我将设计这种对我来说很复杂的布局。这是main_activity.xml文件的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout 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"
tools:context=".MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/home_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/menu_drawer"/>
</android.support.v4.widget.DrawerLayout>
基本上,我的主要活动中有一个导航抽屉和 3 个选项卡。这是一张图片:
一切都如我所愿,我很高兴。
当我单击导航抽屉项目时,我开始一个新的意图来打开一个新活动,这很好,但抽屉当然消失了(因为新活动没有抽屉)。我想把抽屉一直放在屏幕上。
为了让抽屉保持在我的屏幕上,我认为我可以将上述 XML 的 TabLayout 作为片段放置;这样,抽屉仍然在那里。但是我该怎么做呢?如何将 TabLayout 放置在片段中,以便可以将这个片段替换为 TabLayout 或其他片段?
我认为我可以放置一个 FrameLayout 而不是 TabLayout,但我不知道这是否是个好主意以及它会如何工作。有什么帮助吗?
有类似的问题,例如this,但它们并没有帮助我,因为我仍然被困在这里
更多。如果您单击结果,则会启动 ThisSeason 活动,并且其中包含一些片段(包括 ResultsFragments)。这行得通,但没有导航绘图了,我必须按下返回按钮!
【问题讨论】:
标签: android android-fragments navigation-drawer