title: How to use wrap_content with a maximum width?
body: <p>I am trying to layout a view that should wrap its content, but it shouldn't be more than ~100dp less than its parent width. How can I do that using a RelativeLayout or some other layout? What I have right now will always make the view 100dp less than its parent so that there is space for another view. </p>
  
  <p>This picture is an example of what I have:</p>
  
  <p><a href="https://i.stack.imgur.com/TKnp3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/TKnp3.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the text doesn't fill the whole box, so it could be smaller. But, it should never be larger than 100dp less than its parent, so that there is room for the time the message was sent.</p>
  
  <p>This is my layout. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:clipChildren="false"
      android:orientation="vertical"
      android:paddingBottom="10dp"
      android:paddingRight="@dimen/horizontalMargin"
      android:paddingTop="10dp"&gt;
  
  
      &lt;TextView
          android:id="@+id/message_holder"
          android:layout_toLeftOf="@id/blank"
          android:layout_alignParentLeft="true"
          android:layout_marginLeft="@dimen/horizontalMargin"
          android:background="@drawable/message_corners"
          style="@style/white_text"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="alsdkjf; alsdkf" /&gt;
  
      &lt;RelativeLayout
          android:id="@+id/blank"
          android:layout_width="wrap_content"
          android:layout_height="1dp"
          android:layout_alignParentRight="true"
          android:minWidth="100dp"&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;TextView
          android:minWidth="100dp"
          android:id="@+id/time"
          style="@style/gray_text"
          android:layout_toRightOf="@id/message_holder"
          android:paddingLeft="10dp"
          android:text="Yesterday,\n11:30 PM" /&gt;
  
  
      &lt;RelativeLayout
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:layout_alignBottom="@id/message_holder"
          android:layout_alignParentLeft="true"
          android:background="@drawable/triangle" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I have tried using the "minWidth" property on a blank view to the right of the message box to provide spacing, but it doesn't resize to be larger (which would make the message box smaller). When I don't have the blank view, and simply place the time TextView to the right of the message box, then that TextView isn't visible when the message box expands.</p>
  
  <p>Update:</p>
  
  <p>This is my "message_corners.xml":</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle"&gt;
  
  
      &lt;solid
          android:color="@color/green" &gt;
      &lt;/solid&gt;
  
  
      &lt;padding
          android:left="10dp"
          android:top="10dp"
          android:right="10dp"
          android:bottom="10dp"    &gt;
      &lt;/padding&gt;
  
  
      &lt;corners
          android:radius="10dp"&gt;
      &lt;/corners&gt;
  
  &lt;/shape&gt;
  </code></pre>
  
  <p>Update 2:</p>
  
  <p>This is what I am looking for in a layout with short text:</p>
  
  <p><a href="https://i.stack.imgur.com/pUA6k.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pUA6k.png" alt="enter image description here"></a></p>
  
  <p>And this is what I am looking for in a layout with long text:</p>
  
  <p><a href="https://i.stack.imgur.com/J48Ne.png" rel="noreferrer"><img src="https://i.stack.imgur.com/J48Ne.png" alt="enter image description here"></a></p>