gpt4 book ai didi

android - CoordinatorLayout 和隐藏工具栏

转载 作者:行者123 更新时间:2023-11-29 00:08:21 25 4
gpt4 key购买 nike

我正在使用单个 Activity - 多个 fragment 结构。在 Activity 中,我使用 v7 工具栏作为操作栏。我有一些带有 viewpager 的 fragment ,有些也带有标签。在我的一个 fragment 中,我有 recyclerview。我的目标是当我滚动时我想折叠栏并隐藏 float 操作按钮。我的 float 按钮位于 CoordinatorLayout 内部,因此它可以正确显示。但这是在 fragment (它是 viewpager 的一部分),并且 activity_main.xml 有另一个根元素 CoordinatorLayout。 fragment CL 是否拦截 Activity 布局内 CL 的工作,因为当我滚动回收器时没有任何反应。

我应该为每个 fragment 使用新的工具栏还是我可以在 Activity 并为 fragment 实现不同的行为?
任何人都可以引用使用 CoordinatorLayout 和折叠嵌套 fragment 中的栏?

activity_main.xml

    <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:gravity="center"
android:orientation="vertical">

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

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />

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

最佳答案

主要 CoordinatorLayout 的工作没有被拦截。将 app:layout_behavior 添加到作为 fragment 容器的框架布局中完成了这项工作。现在看起来像这样:

    <FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity" />

关于android - CoordinatorLayout 和隐藏工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32141950/

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