title: Android ListView row view with left and right border stretched to height
body: <p>I have an Android ListView which I want to have contain rows with a single <code>TextView</code> with text (<code>titleTextView</code>), and which I want to have a left (<code>leftCellBorder</code>) and right (<code>rightCellBorder</code>) border image which is stretched to fill the height of the row.</p>
  
  <p>The height of the row depends on how much text there is in <code>titleTextView</code>. If the text spills onto a second line, then the two borders should be vertically stretched to fill the height of the border.</p>
  
  <p>So with a single line of text, the row view should look like this:</p>
  
  <p><img src="https://i.stack.imgur.com/1zzZG.png" alt="enter image description here"></p>
  
  <p>With two lines of text, the row view should look this:</p>
  
  <p><img src="https://i.stack.imgur.com/fOnT8.png" alt="enter image description here"></p>
  
  <p>The first version of my XML went like this:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
       &lt;ImageView
           android:id="@+id/leftCellBorder"
           android:layout_width="wrap_content"
           android:layout_height="match_parent"
           android:layout_alignParentBottom="true"
           android:layout_alignParentLeft="true"
           android:layout_alignParentTop="true"
           android:layout_gravity="fill_vertical"
           android:adjustViewBounds="true"
           android:scaleType="fitXY"
           android:src="@drawable/cell_border_left" /&gt;
  
      &lt;TextView
          android:id="@+id/titleTextView"
          android:layout_width="210dp"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:gravity="center"
          android:text="Title"
          android:textSize="30dp" /&gt;
  
      &lt;ImageView
          android:id="@+id/rightCellBorder"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_alignParentBottom="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:adjustViewBounds="true"
          android:scaleType="fitXY"
          android:src="@drawable/cell_border_right" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I thought that having the <code>leftCellBorder</code> and <code>rightCellBorder</code>'s <code>layout_height</code> as <code>match_parent</code> would be enough to ensure they were stretched to be the correct height, but this didn't work and the result I got was as follows:</p>
  
  <p><img src="https://i.stack.imgur.com/TMvxE.png" alt="enter image description here"></p>
  
  <p>i.e. the images are not being stretched to fill the height.</p>
  
  <p>So then I went back and tried to use a horizontal <code>LinearLayout</code> at the root instead of <code>RelativeLayout</code> and had 3 child views. This actually worked, and the left and right borders were properly stretched to fill the height, but then the problem I've had is that there doesn't seem to be a way of clamping the <code>rightCellBorder</code> to the right hand side with a <code>LinearLayout</code> (unless I'm missing something).</p>
  
  <p>So -- how can I achieve the effect I'm looking for? Preferably I would like to stick with <code>RelativeLayout</code> since that gives me more flexibility. Surely this shouldn't be so difficult!</p>