繁体   English   中英

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

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

实际上已经存在类似的问题BringToFront在协调器布局中不起作用

然而,没有任何建议帮助我使bringToFront在Coordinatorlayout中工作。

这是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>

自定义视图继承自FrameLayout。 它可以改变它的高度。

为了首先将自定义视图置于最前面,我尝试添加:

mCustomView.bringToFront();

然后

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

最后也是

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

但没有成功。 按钮仍位于顶部。

我错过了什么吗?

也许有其他可能将自定义视图置于前面或将按钮置于自定义视图下?

我还尝试向按钮添加一个行为,但由于它的可见性不仅取决于自定义视图,而且还抛弃了这种方法。

感谢您提前提供的任何帮助。

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

暂无
暂无

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

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