想要锁定 AppBarLayout 的某些片段

use*_*850 0 android android-appbarlayout

我希望 AppBarLayout 对某些片段保持折叠状态,并对其他片段保持打开状态..基本上,我正在寻找一个函数调用,它将以编程方式使 appbarlayout 折叠/取消折叠....我已经尝试了在此列出的几乎所有方法堆栈在流程页面上,但没有一个对我有用。有人可以帮忙吗?

类似的堆栈溢出页面,在这里尝试了大部分内容但不起作用。 需要禁用某些片段的 CollapsingToolbarLayout 上的扩展

谢谢你的时间

Layout file 


    <?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:fitsSystemWindows="true"
        tools:context="app.com.navact.MainActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/appBarLayout"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>


        <FrameLayout
            android:id="@+id/fragment_container"
            android:orientation="vertical"
            android:paddingTop="0dip"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
         </FrameLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            app:srcCompat="@android:drawable/ic_dialog_email" />

    </android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

kri*_*son 5

您可以调用appBarLayout.setExpanded(true)以展开应用程序栏布局并appBarLayout.setExpanded(false)折叠它。

要将应用栏布局锁定为展开或折叠状态,请调用setNestedScrollingEnabled(false)移动应用栏的滚动视图。该视图将位于片段容器中片段的视图层次结构中的某个位置。