CoordinatorLayout中的Framelayout与Recycleview添加app:layout_behavior不起作用

时间:2016-12-22 02:43:17

标签: android

我有两个XML,education_fragment将添加navigation_drawer_layout

我使用CoordinatorLayout的母容器,并引用一些解决方案将app:layout_behavior="@string/appbar_scrolling_view_behavior"放入Framelayout

它还没有用。

我错过了什么吗?

navigation_drawer_layout:

<?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">
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF">


            <android.support.v7.widget.Toolbar
                android:id="@+id/id_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:theme="@style/ToolBarStyle"
                app:layout_scrollFlags="scroll|enterAlways"
                android:background="@color/colorPrimary">

                <TextView
                    android:id="@+id/textTitle"
                    android:textSize="18dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/background_light" />

            </android.support.v7.widget.Toolbar>

            <FrameLayout
                android:id="@+id/mainFrame"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"></FrameLayout>

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

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@android:color/white"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header"
            app:menu="@menu/drawer_menu" />

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

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

education_fragment:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".SubpagesLayout.Education"
    android:background="@android:color/darker_gray">

    <!-- TODO: Update blank fragment layout -->
    <view
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="android.support.v7.widget.RecyclerView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/educationRecycleView"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</RelativeLayout>

我接受了一些建议并改变了这一点,我的Framelayout可以在工具栏下显示,它现在正在工作。这是我的更改代码

<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/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<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="wrap_content"
        android:background="#FFFFFF">


        <android.support.v7.widget.Toolbar
            android:id="@+id/id_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:theme="@style/ToolBarStyle"
            app:layout_scrollFlags="scroll|enterAlways"
            android:background="@color/colorPrimary">

            <TextView
                android:id="@+id/textTitle"
                android:textSize="18dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@android:color/background_light" />

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

        <FrameLayout
            android:id="@+id/mainFrame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_menu" />


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

0 个答案:

没有答案