title: Trying to understand margins in LinearLayout inside a ScrollView
body: <p>I need to have a <code>LinearLayout</code> inside a <code>SrollView</code> and that <code>LinearLayout</code> must have a margin from the <code>ScrollView</code>. At first, the only way I could think of to solve that issue was having a <code>LinearLayout</code> inside another <code>LinearLayout</code> with the margins set on the this last layout. They wouldn't work if they were set in the outer <code>LinearLayout.</code></p>
  
  <p>Example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:fillViewport="true"
      android:background="@color/layout_color_green"&gt;
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:background="@color/layout_color_yellow"&gt;
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_margin="10dp"
              android:orientation="vertical"
              android:background="@color/layout_color_blue"&gt;
          &lt;/LinearLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/q4BTP.png" alt="enter image description here"></p>
  
  <p>My question is: <strong>Why do I need to do this?</strong></p>
  
  <p>If I had only one <code>LinearLayout</code> there would be no margins...</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:fillViewport="true"
      android:background="@color/layout_color_green"&gt;
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_margin="10dp"
          android:orientation="vertical"
          android:background="@color/layout_color_blue"&gt;
      &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Tw8tr.png" alt="enter image description here"></p>
  
  <p>Then, searching for some similar issue, I found a few layouts which gave me the idea of using padding in the <code>ScrollView</code> instead of margin in the <code>LinearLayout</code>. This also solves my problem and I don't need a <code>LinearLayout</code> inside another one. It's a more elegant solution.</p>
  
  <p>Still, I would like to understand why the simple margin inside the <code>LinearLayout</code> doesn't work when inside a <code>ScrollView</code>. Because it does work fine if it's not inside a <code>ScrollView</code>.</p>
  
  <p>Anyone knows why?</p>