【发布时间】:2016-02-24 00:06:20
【问题描述】:
基于
this 回答我试图为我的用例制定解决方案。我没有使用折叠工具栏,而是使用常规工具栏,但使用TabLayout。但是,对于TabLayout,我需要使用ViewPager,但我不知道将其放置在何处以避免FrameLayout 出现问题。 ViewPager 在我的 Host Fragment 中,当它的布局替换 FrameLayout 时,由于某种原因,内容位于 Toolbar 和 TabLayout 下方...
我试着把它放在那条线下面
<include layout="@layout/content_main" />
在the app_bar_main.xml,但它搞砸了我的用户界面。
真正的问题是,如果我的 Fragment 需要 FrameLayout,而 TabLayout 需要 ViewPager,我该如何实现解决方案?
您可以看到我稍微移动了视图,以便隐藏工具栏。这样,即使在工具栏下方(可见时),ViewPager 也会占用空间
当前尝试 - appbar_content(工具栏只是一个单独布局的工具栏):
<?xml version="1.0" encoding="utf-8"?>
<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.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar" />
<android.support.design.widget.TabLayout
android:visibility="visible"
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/teal"
app:tabGravity="fill"
app:tabIndicatorColor="@color/purple800"
app:tabIndicatorHeight="4dp"
app:itemIconTint="@color/tabicons"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/tealfifty"
app:tabTextAppearance="@style/TabCapsFalse"
app:tabTextColor="@color/iron" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main(删除了 NestedScrollView,因为它搞砸了一切,把我的整个片段视图放在屏幕中间的一个小框架(可能是 50x50 大小)中)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/content_main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" />
我的DrawerLayout:
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include
layout="@layout/appbar_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:fitsSystemWindows="true"
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/tealfifty"
app:itemBackground="@drawable/drawer_item"
app:itemTextColor="@color/drawer_item"
app:itemIconTint="@color/drawer_item"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/navigation_view_items" />
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
标签: android android-viewpager navigation-drawer