在包含布局上使用边距

Use margin on an include layout

这是这个问题的后续问题:

Margin does not impact in "include"

我正在尝试为 include 布局添加边距。我已将 layout_widthlayout_height 添加到 include 元素,但边距仍然被忽略。此外,当我尝试在布局 xml 文件中自动完成单词 "margin" 时,甚至无法识别此属性。

那么如何为 include 标签添加边距?

布局:

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<include
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    layout="@layout/main_status"
     />

<!--
     As the main content view, the view below consumes the entire
     space available using match_parent in both dimensions.
-->

<LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

</LinearLayout>

<!--
     android:layout_gravity="start" tells DrawerLayout to treat
     this as a sliding drawer on the left side for left-to-right
     languages and on the right side for right-to-left languages.
     If you're not building against API 17 or higher, use
     android:layout_gravity="left" instead.
-->
<!--
     The drawer is given a fixed width in dp and extends the full height of
     the container.
-->

<fragment
    android:id="@+id/navigation_drawer"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    tools:layout="@layout/fragment_navigation_drawer" />

如您所见,LinearLayout 的高度设置为 match_parent。我仍然想要那样,但这就是导致包含的布局和容器布局在尝试在我想要包含的布局内添加边距时彼此重叠的原因。

所以我所做的得到我想要的效果是设置线性布局容器的 paddingTop 属性。它在包含的布局和线性布局之间创建了一些 space。