在包含布局

时间:2015-07-08 07:52:48

标签: android android-layout include

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

Margin does not impact in "include"

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

那么如何为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" />

1 个答案:

答案 0 :(得分:1)

如您所见,LinearLayout的高度设置为match_parent。我仍然希望这样,但是当我试图在我想要包含的布局中添加边距时,这就是导致包含的布局和容器布局相互叠加的原因。

所以我所做的就是设置了线性布局容器的paddingTop属性。它在包含的布局和线性布局之间创建了一些空间。

相关问题