简体   繁体   English

在协调器布局中自定义视图的BringToFront

[英]BringToFront of the custom view inside a coordinator layout

Actually there is already similar question BringToFront doesn't work inside a coordinator layout 实际上已经存在类似的问题BringToFront在协调器布局中不起作用

However no of suggestions helped me to make bringToFront work within a coordinatorlayout. 然而,没有任何建议帮助我使bringToFront在Coordinatorlayout中工作。

Here is the layout-xml 这是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. 自定义视图继承自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级别如何,我都可以在其上绘制其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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