title: Android wrap_content too wide when centred text of TextView is long
body: <p>You can use either <code>layout_gravity</code> or <code>gravity</code> for text centring. With <code>layout_gravity</code>:</p>
  
  <pre><code>&lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
      android:breakStrategy="balanced"
  /&gt;
  </code></pre>
  
  <p>Short stretches of text will be displayed as:</p>
  
  <pre><code>[          Hello          ]
  </code></pre>
  
  <p>While long stretches will be: (<em>A</em>)</p>
  
  <pre><code>[ One lemming looking     ]
  [ up.                     ]
  </code></pre>
  
  <p>So you might add:</p>
  
  <pre><code>    android:gravity="center"
  </code></pre>
  
  <p>And you'll get: (<em>B</em>)</p>
  
  <pre><code>[   One lemming looking   ]
  [           up.           ]
  </code></pre>
  
  <p>However, I want to achieve this: (<em>C</em>)</p>
  
  <pre><code>[   One lemming looking   ]
  [   up.                   ]
  </code></pre>
  
  <p><em>A</em> does not look good, because text does not appear centred. This is especially true if there are more centred elements in the layout.</p>
  
  <p><em>B</em> does not look good, because the very short word "up" was put into the centre. Even if the text is longer, it doesn't look good, because the text has two jagged edges (left + right) instead of just one (to the right).</p>
  
  <p><em>C</em> is the same as <em>A</em>, but correctly centred. The reason why <em>A</em> does not look centred is because <code>wrap_content</code> assumes the width of the TextView is as wide as the parent's when the text wraps on another line, and does not compute the <em>actual</em> width of the block of text.</p>
  
  <p>So, how do I achieve <em>C</em>? Is it possible?</p>
  
  <p>Here's the full layout:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginLeft="32dp"
  android:layout_marginRight="32dp"
  &gt;
  &lt;FrameLayout
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
  /&gt;
  &lt;TextView
      android:id="@+id/primary_form"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
      android:gravity="start"
      android:textAppearance="@style/TextAppearance.AppCompat.Headline"
      android:textColor="@color/text_primary_on_lt"
      android:breakStrategy="balanced"
      tools:text="Primary form adfahdkahdfa "
  /&gt;
  &lt;TextView
      android:id="@+id/secondary_form"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
      android:layout_marginTop="8dp"
      android:textAppearance="@style/TextAppearance.AppCompat.Large"
      android:textColor="@color/text_secondary_on_lt"
      android:textStyle="italic"
      android:typeface="serif"
      android:breakStrategy="balanced"
      tools:text="Secondary form"
  /&gt;
  &lt;FrameLayout
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
  /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>