java负边距布局覆盖父布局
我有一个活动,它有一个工具栏和一个框架布局,我可以在其中插入片段
以下是该活动的布局:
<安卓.support.v4.widget.DrawerLayout
安卓:id="@+id/drwDrawerRoot"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="@drawable/background_main_selector"
安卓:theme="@style/AppTheme">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="vertical">
<include
安卓:id="@+id/viewMainToolbar"
layout="@layout/view_toolbar" />
</LinearLayout>
<FrameLayout
安卓:id="@+id/frmDrawerContainer"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_marginTop="@dimen/toolbar_height"
安卓:clipChildren="false"
安卓:clipToPadding="false"
安卓:orientation="vertical" />
<include
安卓:id="@+id/viewDrawer"
layout="@layout/view_drawer"
bind:name="@{name}"/>
<include
安卓:id="@+id/viewUserDrawer"
layout="@layout/view_user_drawer"
bind:name="@{name}"/>
</安卓.support.v4.widget.DrawerLayout>
我有一个带边距的框架布局,这样片段中的内容就不会覆盖工具栏,但是我根据我在这里看到的一些其他帖子,将clipChildren和clipToPadding设置为false
然而,在一些片段上,我有一个加载视图,我想占据整个屏幕
这是一个样本片段:
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<LinearLayout
安卓:id="@+id/layout_main"
style="@style/Layout.FullScreen"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_above="@+id/layout_footer"
安卓:orientation="vertical">
<TextView
安卓:id="@+id/textView7"
style="@style/Text.Header"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:text="@string/login_header" />
<EditText
安卓:id="@+id/edtMessage"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:elevation="1dp"
安卓:ems="10"
安卓:inputType="textMultiLine" />
<Button
安卓:id="@+id/btnSend"
style="@style/Button.Primary"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:text="@string/support_button" />
</LinearLayout>
<LinearLayout
安卓:id="@+id/layout_footer"
style="@style/Layout.FullScreen.Footer"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_alignParentBottom="true"
安卓:orientation="vertical">
<TextView
安卓:id="@+id/footerInfo"
style="@style/Text.White.Small.Centered"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:text="@string/footer_info" />
</LinearLayout>
<include
layout="@layout/view_loading"
安卓:visibility="invisible"
bind:loading="@{loading}" />
</RelativeLayout>
Ans这是包含的加载视图,我将其设置为负边距,希望它能移动到屏幕顶部:
<FrameLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_marginTop="-40dp"
安卓:background="@color/colorLoadingBackground"
安卓:clickable="true"
安卓:visibility="@{loading ? View.VISIBLE : View.GONE}">
</FrameLayout>
我错过什么了吗
这是可行的还是我需要改变我的做法
澄清: 第一个/根布局包括一个工具栏,第二个布局包括在第一个布局的框架布局中。这意味着第二个布局的内容从工具栏下方开始。但是,我希望第三个布局(第二个布局中包含的加载屏幕)具有负边距,以便覆盖整个屏幕,而不仅仅是从工具栏下方开始
# 1 楼答案
你需要使用
CoordinatorLayout
那么你就不需要负的边距了。以下是您可以根据需要定制的布局示例