负余量布局为覆盖父母布局



我有一个具有工具栏和一个framelayout的活动,我注入了片段。

这是该活动的布局:

<android.support.v4.widget.DrawerLayout
        android:id="@+id/drwDrawerRoot"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background_main_selector"
        android:theme="@style/AppTheme">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <include
                android:id="@+id/viewMainToolbar"
                layout="@layout/view_toolbar" />
        </LinearLayout>
        <FrameLayout
            android:id="@+id/frmDrawerContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/toolbar_height"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:orientation="vertical" />
        <include
            android:id="@+id/viewDrawer"
            layout="@layout/view_drawer"
            bind:name="@{name}"/>
        <include
            android:id="@+id/viewUserDrawer"
            layout="@layout/view_user_drawer"
            bind:name="@{name}"/>
    </android.support.v4.widget.DrawerLayout>

我的framelayout具有边距,因此片段中的内容不会覆盖工具栏,但是我根据我在这里看到的其他一些帖子将clipchildren和cliptopadding设置为false。

在某些片段上,我有一个加载视图,我想占据所有屏幕。

这是一个样本片段:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:id="@+id/layout_main"
            style="@style/Layout.FullScreen"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/layout_footer"
            android:orientation="vertical">
            <TextView
                android:id="@+id/textView7"
                style="@style/Text.Header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/login_header" />
            <EditText
                android:id="@+id/edtMessage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:elevation="1dp"
                android:ems="10"
                android:inputType="textMultiLine" />
            <Button
                android:id="@+id/btnSend"
                style="@style/Button.Primary"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/support_button" />
        </LinearLayout>
        <LinearLayout
            android:id="@+id/layout_footer"
            style="@style/Layout.FullScreen.Footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="vertical">
            <TextView
                android:id="@+id/footerInfo"
                style="@style/Text.White.Small.Centered"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/footer_info" />
        </LinearLayout>
        <include
            layout="@layout/view_loading"
            android:visibility="invisible"
            bind:loading="@{loading}" />
    </RelativeLayout>

ans这是所包含的加载视图,我将其设置为负余量,希望它可以向上移至屏幕顶部:

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="-40dp"
        android:background="@color/colorLoadingBackground"
        android:clickable="true"
        android:visibility="@{loading ? View.VISIBLE : View.GONE}">
    </FrameLayout>

我在这里错过了什么吗?

这是可行的还是我需要改变自己的操作方式?

澄清:第一个/根布局包括一个工具栏,第二个布局包含在第一个框架布局中。这意味着第二个布局的内容从工具栏下方开始。但是,我希望第三个布局(第二个布局中包含的加载屏幕)具有负余量,以使其整个屏幕覆盖,而不仅仅是在工具栏下方开始。

您需要使用CoordinatorLayout,然后您不需要负余量。这是您可以根据需要自定义的示例布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:layout_behavior= "@string/appbar_scrolling_view_behavior">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                app:title="My App" />
        </android.support.design.widget.AppBarLayout>
        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
        <!--include a full screen loading layout here and hide/show according to your need-->
        <include layout="@layout/loading_layout/>
    </android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"/>
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

最新更新