Android 要锁定某些片段的AppBarLayout吗
我希望AppBarLayout对一些片段保持折叠状态,对另一些片段保持打开状态。基本上,我正在寻找一个函数调用,该函数调用将通过编程方式使AppBarLayout折叠/取消折叠。。。。我已经尝试了这个流堆栈页面上列出的几乎所有方法,但没有一种对我有效。有人能帮忙吗 类似于流页面上的堆栈,在这里尝试了大部分内容,但不起作用。。 谢谢你的时间Android 要锁定某些片段的AppBarLayout吗,android,android-appbarlayout,Android,Android Appbarlayout,我希望AppBarLayout对一些片段保持折叠状态,对另一些片段保持打开状态。基本上,我正在寻找一个函数调用,该函数调用将通过编程方式使AppBarLayout折叠/取消折叠。。。。我已经尝试了这个流堆栈页面上列出的几乎所有方法,但没有一种对我有效。有人能帮忙吗 类似于流页面上的堆栈,在这里尝试了大部分内容,但不起作用。。 谢谢你的时间 Layout file <?xml version="1.0" encoding="utf-8"?> <androi
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>
布局文件
您可以调用appBarLayout.setExpanded(true)
来展开appbar布局,也可以调用appBarLayout.setExpanded(false)
来折叠它
要将应用程序栏布局锁定为展开或折叠状态,请在移动应用程序栏的滚动视图上调用
setNestedScrollingEnabled(false)
。该视图将位于片段容器中片段的视图层次结构中的某个位置。您可以调用appBarLayout.setExpanded(true)
来展开appbar布局,也可以调用appBarLayout.setExpanded(false)
来折叠它
要将应用程序栏布局锁定为展开或折叠状态,请在移动应用程序栏的滚动视图上调用
setNestedScrollingEnabled(false)
。该视图将位于片段容器中片段的视图层次结构中的某个位置。此解决方案可以工作,但如果您点击折叠的工具栏并向下滑动,它就会这样做,因为此解决方案只锁定嵌套的滚动,只需将工具栏合并。我现在面临着这个问题,还有另一个问题,我发布了。如果您有任何想法可以帮助我解决我的问题,我将非常感谢您。这种解决方案是有效的,但如果您点击折叠的工具栏并向下滑动,它就会成功,因为这种解决方案只锁定嵌套的滚动条,只需将工具栏合并。我现在面临着这个问题,还有另一个问题,我发布了。如果你有任何想法来帮助我解决我的问题,我将非常感谢你。