简体   繁体   中英

BringToFront of the custom view inside a coordinator layout

Actually there is already similar question BringToFront doesn't work inside a coordinator layout

However no of suggestions helped me to make bringToFront work within a coordinatorlayout.

Here is the layout-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>

The custom view is inherited from FrameLayout. It can change its height.

To bring the custom view to the front first I tried to add:

mCustomView.bringToFront();

Then

mCustomView.requestLayout();
mCustomView.invalidate();

Finally also

((View)mCustomView.getParent()).requestLayout();

But without success. The button is still on the top.

Did I missed anything?

Maybe there other possibilities to bring the custom view to front or to put the button under custom view?

I also tried to add a behaviour to the button, but since it's visibility depends not only on the custom view I thrown this approach away.

Thank you for any help in advance.

我终于找到了一个解决方法 - 如果我在AppBar上设置setEnabled(false) ,它会转到后台,无论API级别如何,我都可以在其上绘制其他内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM