【问题标题】:Want to lock AppBarLayout for some fragments想为某些片段锁定 AppBarLayout
【发布时间】:2017-05-10 12:42:18
【问题描述】:

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

流页面上的类似堆栈,在这里尝试了大多数东西,但没有工作.. Need to disable expand on CollapsingToolbarLayout for certain fragments

感谢您的宝贵时间

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>

【问题讨论】:

    标签: android android-appbarlayout


    【解决方案1】:

    你可以调用appBarLayout.setExpanded(true)展开应用栏布局,调用appBarLayout.setExpanded(false)折叠它。

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

    【讨论】:

    • 此解决方案有效,但如果您点击折叠的工具栏并向下滑动,它会这样做,因为此解决方案仅锁定嵌套滚动并仅折叠工具栏。我目前正面临这个问题以及我发布的另一个问题here。如果您有任何想法可以帮助我解决我的问题,我将非常感谢您。
    猜你喜欢
    • 2017-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多