DrawerLayout + CollapsingToolbar +片段;工具栏不会折叠或显示图像 [英] DrawerLayout + CollapsingToolbar + Fragments; Toolbar won't collapse or show image

查看:75
本文介绍了DrawerLayout + CollapsingToolbar +片段;工具栏不会折叠或显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,我有一个活动,其中有一个容纳我的FragmentsFrameLayout [我不使用制表符,而只是使用交易].我也有一个NavigationDrawerToolbar.所有这些事情都可以正常工作.

As the title suggests, I have an activity that has a FrameLayout that houses my Fragments [I am NOT using a Tabs, just Transactions]. I also have a NavigationDrawer and Toolbar. All of these things work fine.

问题是我正在尝试在Activity布局中添加CollapsingToolbarLayout并在Fragment滚动中包含RecyclerView并控制CollapsingToolbarLayout的折叠.

The issue is that I'm trying to add a CollapsingToolbarLayout to the Activity layout and have RecyclerView in the Fragment scroll and control the collapsing of the CollapsingToolbarLayout.

使用下面显示的设置,我可以使用NavigationDrawer,请参见Toolbar和展开的CollapsingToolbarLayout,其中没有图像(那里有奇怪的问题).我将Fragment加载到FrameLayout中,其中包含一个包含10个测试视图的RecyclerView.可以在CollapsingToolbar下面滚动良好,但不会折叠.

With the setup shown below, I'm able to use the NavigationDrawer, see the Toolbar and the expanded CollapsingToolbarLayout with NO image inside (odd issue there). I load the Fragment into the FrameLayout which contains a RecyclerView with 10 test views. This scrolls fine below the CollapsingToolbar but it does not collapse.

<android.support.v4.widget.DrawerLayout
    android:id="@+id/dl_drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/cl_dashboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/abl_dashboard"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/ctb_dashboard"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="@color/the_color"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:id="@+id/iv_dashboard_header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:src="@mipmap/the_image"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="parallax"/>

                <include
                    android:id="@+id/toolbar"
                    layout="@layout/overlay_toolbar"
                    app:layout_collapseMode="pin"/>

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

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

        </FrameLayout>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/nv_navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/overlay_drawer_header"
        app:menu="@menu/menu_drawer"/>
</android.support.v4.widget.DrawerLayout>

片段布局XML

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_fragment_dashboardhome"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

我不明白为什么这行不通,并且我浏览了很多文档和示例,但运气不佳.任何帮助或建议,将不胜感激.

I don't understand why this isn't working and I've run through a lot of documentation and examples with no luck. Any help or suggestion would be greatly appreciated.

推荐答案

原来,我为Toolbar使用的布局没有正确的高度值.

It turned out that the layout I was using for the Toolbar did not have the correct height value.

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/get_blue"
    android:elevation="5dp"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/actionbar_getblue">

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

对overlay_toolbar的调整包括在Activity XML中的调用

<include
    android:id="@+id/toolbar"
    layout="@layout/overlay_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_collapseMode="pin"/>

对高度进行一次调整后,CollapsingToolbarLayout开始正常工作.

After that single adjustment to the height the CollapsingToolbarLayout began working perfectly.

这篇关于DrawerLayout + CollapsingToolbar +片段;工具栏不会折叠或显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆