title: Android: When to use layout_margin, when to use weightSum?
body: <p>I am trying to achieve the following layout on my Android app:</p>
  
  <p><img src="https://i.stack.imgur.com/m0ae5.jpg" alt="enter image description here"></p>
  
  <p>As you can see I want a central login box taking about 70% of the width. I believe there are basically two approaches to achieve this:</p>
  
  <p><strong>1.</strong> Create a Linear or Relative layout for the login box, and add layoutMargin both on the left and right sides.</p>
  
  <p><strong>2.</strong> Create a wrapper LinearLayout with weightSum="1", and then place the RelativeLayout inside it with layout_width="0dp" and layout_weight="0.7". </p>
  
  <p>Using the first approach the XML would look like this:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
      &lt;ImageView
          android:layout_gravity="center"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"        
          android:src="@drawable/logo"
          android:contentDescription="@string/logo"  
           /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"         
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:background="#999999"
          android:gravity="center"
          android:layout_margin="30dp"
           &gt;
          &lt;EditText
              android:layout_width="fill_parent"           
              android:layout_height="wrap_content"
              android:layout_marginTop="20dp"
              android:layout_marginLeft="20dp"
              android:layout_marginRight="20dp"
              android:hint="@string/email" /&gt;
          &lt;EditText
              android:layout_width="fill_parent"            
              android:layout_height="wrap_content"
              android:layout_marginLeft="20dp"
              android:layout_marginRight="20dp"
              android:hint="@string/password" /&gt;
          &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"  
              android:text="@string/login"/&gt;
  
  
      &lt;/LinearLayout&gt;     
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The second approach would just have a wrapper LinearLayout on top of the current one, with weightSum="1", and the internal layout would get a layout_weight="0.7" attribute.</p>
  
  <p>Which one do you think is the best approach? Thanks in advance.</p>