Android - 强制视图出现在工具栏前面?

Android - Force View to appear in front of Toolbar?

默认情况下,例如。在 FrameLayout 容器中拥有工具栏和其他一些视图会导致工具栏出现在其他视图之上,无论它们的(视图)顺序是什么。

是否可以强制某些视图(例如浮动操作按钮)出现在工具栏前面,或者应该寻找解决方法?

编辑:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:fab="http://schemas.android.com/apk/res-auto"
             android:layout_width="match_parent"
             android:layout_height="match_parent">

    <include layout="@layout/toolbar"/>

    <!-- some RecyclerView goes here also -->

    <com.github.clans.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|right"
        android:src="@drawable/ic_content_add"
        fab:fab_colorNormal="@color/accentColor"
        fab:fab_colorPressed="@color/accentColor"
        android:layout_marginRight="20dp"
        />
</FrameLayout>

结果:

问题:椭圆按钮出现在RecyclerView的前面,但是在Toolbar的后面。

浮动操作按钮的 elevation 必须等于或高于工具栏。假设您的工具栏的高度设置为 8dp,FAB 至少需要具有相同的高度。

基本上,海拔较高的小部件会在物理上移动并停止遵守 XML 顺序。