实际上已经有类似的问题:BringToFront在coordinatorlayout内不起作用
然而,没有建议能够帮助我使bringToFront在coordinatorlayout内起作用。
这是布局XML:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/main_content_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment
android:id="@+id/navigation_drawer_container"
android:name="..."
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/..."
android:clickable="true"
android:layout_gravity="bottom|end"
android:layout_marginRight="20dp"
android:layout_marginBottom="60dp"
app:borderWidth="0dp"/>
<CustomView
android:id="@+id/customview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="gone"
app:layout_behavior="..."/>
</android.support.design.widget.CoordinatorLayout>
这个自定义视图继承自FrameLayout,可以改变它的高度。
想要将自定义视图放到最前面,我首先尝试添加了以下代码:
mCustomView.bringToFront();
那么
mCustomView.requestLayout();
mCustomView.invalidate();
最后也同样重要。
((View)mCustomView.getParent()).requestLayout();
但是没有成功。按钮仍然在顶部。
我错过了什么吗?
也许还有其他可能将自定义视图置于前端或将按钮放在自定义视图下面?
我还尝试为按钮添加行为,但由于其可见性不仅取决于自定义视图,我放弃了这种方法。
提前感谢您的任何帮助。