gpt4 book ai didi

android - DrawerLayout + CollapsingToolbar + fragment ;工具栏不会折叠或显示图像

转载 作者:搜寻专家 更新时间:2023-11-01 08:40:27 26 4
gpt4 key购买 nike

正如标题所暗示的,我有一个具有 FrameLayout 的 Activity 那是我的Fragments [我没有使用标签,只是交易]。我还有一个 NavigationDrawerToolbar .所有这些都工作正常。

问题是我正在尝试添加 CollapsingToolbarLayoutActivity布局并有RecyclerViewFragment滚动并控制 CollapsingToolbarLayout 的折叠.

通过如下所示的设置,我可以使用 NavigationDrawer , 请参阅 Toolbar和扩展的 CollapsingToolbarLayout里面没有图像(那里有奇怪的问题)。我加载 Fragment进入FrameLayout其中包含 RecyclerView有 10 个测试 View 。这可以在 CollapsingToolbar 下方正常滚动,但不会折叠。

Activity 布局 XML

<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>

fragment 布局 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>

我不明白为什么这行不通,而且我浏览了很多文档和示例,但都没有成功。任何帮助或建议将不胜感激。

最佳答案

事实证明,我为 Toolbar 使用的布局没有正确的高度值。

overlay_toolbar.xml

<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 include在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 开始完美运行。

关于android - DrawerLayout + CollapsingToolbar + fragment ;工具栏不会折叠或显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33132908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com