【发布时间】:2020-01-24 12:00:49
【问题描述】:
到目前为止,我已经成功地实现了带有滚动标志和 AppBar 滚动行为的 AppBarLayout 和 Toolbar,而且一切都很好。我的最终目标是实现这样的东西:
如您所见,AppBar 是透明的,内容在其背后。其他一切都完美无缺。
根据我在放置 app:layout_behavior="@string/appbar_scrolling_view_behavior" 时的观察结果(在我的情况下,我使用了 app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior")标签 CoordinatorLayout 不允许我重叠视图(在这种情况下 AppBar 应该重叠我的内容)。
这是我的 XML:
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<fragment
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="@navigation/root_nav_graph"
app:defaultNavHost="true"
/>
</FrameLayout>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
>
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap"
/>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
片段包含以 NestedScrollView 作为根的布局。
【问题讨论】:
-
嘿,你找到解决办法了吗?
-
不,不幸的是我没有。我放弃了这个,因为我不能再花更多的时间来解决这个问题。我希望有人找到解决方案。此外,最可能需要自定义布局行为类。
-
我也在寻找这样的东西。有什么想法吗?
-
我会在我的下一个项目中做这样的事情,我会及时告诉你进展如何:)
标签: android android-layout android-toolbar android-appbarlayout