CodeMonkey
CodeMonkey

Reputation: 12434

Use margin on an include layout

This is a follow up question to this question:

Margin does not impact in "include"

I am trying to add a margin to an include layout. I have added layout_width and layout_height to the include element, but the margin is still ignored. Furthermore, when I try to auto complete the word "margin" in the layout xml file, this attribute is not even recognized.

So how can I add a margin to an include tag?

The layout:

<!-- 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" />

Upvotes: 5

Views: 4544

Answers (1)

CodeMonkey
CodeMonkey

Reputation: 12434

As you can see, the LinearLayout's height is set to match_parent. I still want it like that, but that's what caused the included layout and container layout be on top of each other when trying to add margin inside the layout that I wanted to include.

So what I did that got me the effect I wanted was setting the paddingTop attribute of the linear layout container. It created some space between the included layout and the linear layout.

Upvotes: 1

Related Questions