title: Getting calculated width of a button with Java (returns -2?)
body: <p>I want to set the width and height of a progress circle to the height of the item next to it, a button. In the end I want to have a circle with equal height and width, that occupies the total height of the search button - if there's an easier way to do that, please tell me. </p>
  
  <p>I guess this cannot be done using simple XML, so I'm trying to use <code>LayoutParams</code> for this, in the <code>OnCreate()</code> function of my activity:</p>
  
  <pre><code>LayoutParams lpe = search.getLayoutParams();
  LayoutParams lpp = searchProgress.getLayoutParams();
  lpp.width = lpe.height;
  lpp.height = lpp.width;
  Toast.makeText(getBaseContext(),"Width: "+lpp.width,Toast.LENGTH_LONG).show();
  Toast.makeText(getBaseContext(),"Height: "+lpp.height,Toast.LENGTH_LONG).show();
  searchProgress.setLayoutParams(lpp);
  </code></pre>
  
  <p>This doesn't work for the width, however it does work for the height. I added the toasts to see some debugging info. Both <code>lpp.width</code> and <code>lpp.height</code> are <code>-2</code>. What does that mean? Here's the XML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Button
      android:id="@+id/searchButton"
      style="?android:attr/buttonStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignBottom="@+id/searchProgress"
      android:layout_alignTop="@+id/searchProgress"
      android:layout_toLeftOf="@+id/searchProgress"
      android:text="@string/searchButton" /&gt;
  
  &lt;ProgressBar
      android:id="@+id/searchProgress"
      style="?android:attr/progressBarStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignBottom="@+id/searchBar"
      android:layout_alignRight="@+id/searchResult"
      android:layout_alignTop="@+id/searchBar"
      android:indeterminate="true"
      android:indeterminateBehavior="repeat" /&gt;
  </code></pre>
  
  <p>According to <a href="http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#attr_android%3alayout_width" rel="nofollow">this</a> <code>-2</code> means <code>wrap_content</code>. But I don't want to have the height as it is in the XML, I can see that myself. I want the height <em>calculated by the device</em>. </p>
  
  <p>How can I get this to work?</p>