【问题标题】:Fragment's layout being covered up by activity's toolbar/tablayout片段的布局被活动的工具栏/标签布局覆盖
【发布时间】:2016-03-10 22:12:55
【问题描述】:

我有一个带有导航抽屉的单个活动应用程序,用于在几个片段之间导航。该活动还有一个工具栏和一个选项卡布局,我拥有它,以便选项卡在可见性消失之前保持隐藏,直到切换到带有视图寻呼机的片段。问题是选项卡片段的内容隐藏在工具栏和选项卡显示下方。有任何想法吗?

主要活动布局:

<android.support.v4.widget.DrawerLayout
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:id="@+id/main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:visibility="visible">

        <include
            android:id="@+id/my_toolbar"
            layout="@layout/app_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_alignParentLeft="false"
            android:layout_alignParentTop="true"
            app:layout_scrollFlags="enterAlways">
        </include>

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@color/colorPrimary"
            android:id="@+id/TabsDisplay"
            app:tabMode="scrollable"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:visibility="gone"/>
    </android.support.design.widget.AppBarLayout>


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/container"/>
    </FrameLayout>

<!--The drawer stuff is below -->
<android.support.design.widget.NavigationView
    android:id="@+id/main_navDrawer"
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_drawer_header"
    app:itemIconTint="@color/colorAccent"
    app:itemTextColor="@color/colorSecondary_text"
    app:menu="@menu/menu_nav_drawer"/>

工具栏布局:(我只是通过不同的尝试将其分开,从未将其重新合并。)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/abc_action_bar_default_height_material"
    android:background="@color/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:layout_scrollFlags="enterAlways"/>

我有一个基本布局作为“介绍页面”,现在只显示一个文本视图,该文本视图在启动时被放入容器中,通过导航抽屉被其他片段替换。其中一个有一个viewpager,它可以显示标签布局,标签显示并正确加载文本和片段,但它们被工具栏/标签栏覆盖。我曾尝试将 tablayout 直接放入片段中,但它根本没有显示,并且无法找到正确的方法来执行此操作。

选项卡式/Viewpager 片段:

<?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"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

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

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

【问题讨论】:

    标签: android android-layout android-activity android-tabs


    【解决方案1】:

    使用相对布局并为 FrameLayout 赋予以下属性:

    android:layout_below="@+id/toolbar"
    

    确保先将 ID 添加到工具栏

    【讨论】:

      【解决方案2】:

      U 可以使用 RelativeLayout 代替层次结构中的第一个 FrameLayout,并将 Fragment 容器对齐到 AppBarLayout 下方。 "android:layout_below="@id/appBarLayout"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-11
        • 1970-01-01
        相关资源
        最近更新 更多