title: Aligning text in the centre of the screen between 2 buttons, one of which might not be visible
body: <p>This is difficult to explain, please bear with me.</p>
  
  <p>I have a top menu bar in a design which has been given to me (it's a port).</p>
  
  <p>The menu bar has two buttons, one on the left of the menu, one on the right, and a text title between the two buttons.  </p>
  
  <p>The text view is single line so that if the text is longer than the view, it shortens with an ellipsis at the end.  The text should be centred within the display width between the buttons.  The text is a title for the current content and it's OK that it might be shortened.  In practice, on most devices, only the odd letter or two gets chopped off.</p>
  
  <p>If both buttons are visible, then it's very straightforward however, depending on where I am in the app, the right button might not be visible.  When it's not visible, I use View.GONE.  The problem is that the text now fills the remaining space, which is desired, but centres in that remaining space, not within the display width so that a short piece of text is offset to the right by the width of the first button.</p>
  
  <p>Using View.INVISIBLE rather than View.GONE is not the answer as the text then centres correctly but doesn't use the available space to minimise the shortening of the text.</p>
  
  <p>Here's the effect I'm trying to achieve:</p>
  
  <p>Both buttons visible:</p>
  
  <pre><code>---------------------------------------------------------------
  | Left button |  Title text centred in display | Right button |
  ---------------------------------------------------------------
  </code></pre>
  
  <p>Right button hidden</p>
  
  <pre><code>---------------------------------------------------------------
  | Left button |  Title text centred in display                |
  ---------------------------------------------------------------
  </code></pre>
  
  <p>Right button hidden with long text showing elipsis.  This is what I'm looking for.</p>
  
  <pre><code>---------------------------------------------------------------
  | Left button |  A really long piece of title text centred ...|
  ---------------------------------------------------------------
  </code></pre>
  
  <p>Here's what I'm getting when i hide the right button, note that the text is not centred.</p>
  
  <pre><code>---------------------------------------------------------------
  | Left button |        Title text centred in this space       |
  ---------------------------------------------------------------
  </code></pre>
  
  <p>Here's the layout I'm using currently.</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:background="@drawable/activitytitlegradient"    
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" 
      android:orientation="horizontal"    
      android:gravity="center_vertical"&gt;
  
     &lt;ImageView android:id="@+id/mainMenuLeftButton" 
                  android:background="#00ffffff"
                  android:layout_gravity="center_vertical"        
              android:src="@drawable/rr_boat_bow"
              android:scaleType="fitStart"        
              android:layout_weight="1"   
              android:layout_height="34dip"
              android:layout_width="wrap_content"/&gt;
  
     &lt;TextView  android:id="@+id/mainMenuTitle"
                      android:layout_weight="10"
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content"        
              android:paddingLeft="2dp"
              android:background="#00ffffff"          
              android:text="Reference"
              android:singleLine="true"
              android:textSize="19sp"
              android:textStyle="bold" 
              android:textColor="#ffffff"     
              android:gravity="center_horizontal|center_vertical" /&gt;
  
  
      &lt;Button android:id="@+id/mainMenuRightButton" 
              android:background="@drawable/buttonborder"
              android:text="Edit"     
              android:textSize="13sp"
              android:textColor="#ffffff"
              android:textStyle="bold"
              android:layout_margin="3dip"
              android:padding="3dip"
              android:layout_weight="1"                   
              android:layout_height="35dip"
              android:layout_width="wrap_content"
              android:visibility="gone"/&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The first button is implemented as an ImageView to enable some other (non relevant) effects I'm doing elsewhere.  The text is hard coded only to help with laying out.  My code changes the text as needed.</p>
  
  <p>I can do this with a custom view but I am sure there must be a way to do this with the standard framework.</p>
  
  <p>Thank you for any clues...</p>