title: How does one create Buttons with Equal Widths?
body: <p>I want to display three buttons in the middle of a screen, and have the three buttons all be the same width, though they will have text labels of different lengths.</p>
  
  <p>Just adding three buttons with text labels of different lengths produces buttons of different widths.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center_vertical"
      android:gravity="center"&gt;
      &lt;Button
          android:id="@+id/button_1"
          android:layout_height="fill_parent"
          android:layout_width="wrap_content"
          android:text="ABCDEF" /&gt;
      &lt;Button
          android:id="@+id/button_2"
          android:layout_height="fill_parent"
          android:layout_width="wrap_content"
          android:text="GHI" /&gt;
      &lt;Button
          android:id="@+id/button_3"
          android:layout_height="fill_parent"
          android:layout_width="wrap_content"
          android:text="JKLM" /&gt;
  &lt;/LinearLayout&gt;</code></pre>
  
  <p>default button width wraps contents:<br />
  <img src="https://lh5.googleusercontent.com/_VZJksQ6kepc/TZCBDHm02DI/AAAAAAAAAC4/yJ9HlG4wdDQ/s800/default_button_width_wraps_contents.png" alt="default button width wraps contents" /></p>
  
  <p>--</p>
  
  <p>Setting the layout_weight to 1 and the layout_width to 0dip on all the buttons causes them to stretch equally to fill the entire screen width.  For what I want, such buttons are simply too big, especially on large screens.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center_vertical"
      android:gravity="center"&gt;
      &lt;Button
          android:id="@+id/button_1"
          android:layout_height="fill_parent"
          android:layout_width="0dip"
          android:layout_weight="1"
          android:text="ABCDEF" /&gt;
      &lt;Button
          android:id="@+id/button_2"
          android:layout_height="fill_parent"
          android:layout_width="0dip"
          android:layout_weight="1"
          android:text="GHI" /&gt;
      &lt;Button
          android:id="@+id/button_3"
          android:layout_height="fill_parent"
          android:layout_width="0dip"
          android:layout_weight="1"
          android:text="JKLM" /&gt;
  &lt;/LinearLayout&gt;</code></pre>
  
  <p>layout weight 1 buttons fill screen width:<br />
  <img src="https://lh4.googleusercontent.com/_VZJksQ6kepc/TZCBDL7bqnI/AAAAAAAAAC8/w_aNgHvFRIU/s800/layout_weight_1_buttons_fill_screen_width.png" alt="layout weight 1 buttons fill screen width" /></p>
  
  <p>--</p>
  
  <p>Setting different values for weightSum in the parent LinearLayout can be used to stop the buttons from filling the entire screen, but I don't think this is the path I want to take, because I don't want the buttons to occupy a large portion of the screen on large screen devices.  To clarify, using weightSum, I could, for example, set the three buttons to collectively occupy half the screen width, which may look OK on small screens, but on a large screen, the buttons would still occupy half the screen width, and the buttons would simply be much larger than what I want.  Perhaps the final solution will be to simply have different layout files for different screens, but I'd rather not go down this path.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center_vertical"
      android:gravity="center"
      android:weightSum="5"&gt;
      &lt;Button
          android:id="@+id/button_1"
          android:layout_height="fill_parent"
          android:layout_width="0dip"
          android:layout_weight="1"
          android:text="ABCDEF" /&gt;
      &lt;Button
          android:id="@+id/button_2"
          android:layout_height="fill_parent"
          android:layout_width="0dip"
          android:layout_weight="1"
          android:text="GHI" /&gt;
      &lt;Button
          android:id="@+id/button_3"
          android:layout_height="fill_parent"
          android:layout_width="0dip"
          android:layout_weight="1"
          android:text="JKLM" /&gt;
  &lt;/LinearLayout&gt;</code></pre>
  
  <p>weight sum 5 small screen:<br />
  <img src="https://lh6.googleusercontent.com/_VZJksQ6kepc/TZCBDchoZZI/AAAAAAAAADE/V9-uL9suux0/s800/weight_sum_5_small_screen.png" alt="weight sum 5 small screen" /></p>
  
  <p>weight sum 5 large screen:<br />
  <img src="https://lh3.googleusercontent.com/_VZJksQ6kepc/TZCBDMZmXAI/AAAAAAAAADA/ik_vpD3UWOQ/s800/weight_sum_5_large_screen.png" alt="weight sum 5 large screen" /></p>
  
  <p>--</p>
  
  <p>I also tried many things with TableLayout, but didn't get anything better than just using LinearLayout.</p>
  
  <p>GridView is extra-clumsy to use, and I haven't tried it, yet.</p>
  
  <p>So, how does one create buttons with equal widths, preferrably where they are only as wide as necessary to fit the contents of the button with the longest label?</p>
  
  <p>Any advice is appreciated.</p>
  
  <p>(I did search and find this question asked and answered many times, but none of the answers I found resolved what I'm trying to achieve.)</p>