title: How to size Android components according to image size using XML
body: <p>I have created a custom icon bar in Android using the XML layout creator, using a RadioGroup within a LinearLayout (XML included below).  Each RadioButton within the RadioGroup has a custom drawable (with checked and unchecked states) as its <code>android:button</code> attribute.  </p>
  
  <p>The Linear layout is itself within a <code>RelativeLayout</code> so that it can appear at an arbitrary position on the screen (as a side bar, in this instance).</p>
  
  <p>The drawables are 55 pixels wide, and the <code>android:layout\_width</code> attribute of all these views is <code>wrap\_content</code>.</p>
  
  <p>When I make this component visible, aligned to the bottom-left of the screen, only about three-quarters of the RadioButton image widths are visible.  Setting the <code>layout\_width</code> of the <code>RelativeLayout</code> to <code>fill\_parent</code>  rectifies this and causes the full button to appear.</p>
  
  <p>However this means that the button group consumes click events across the entire width of the screen.</p>
  
  <p>How can I make the entire button appear, and have only the area of the button respond to clicks?  Hard-coding the width of the drawable is not a particularly desirable solution.</p>
  
  <pre><code>&lt;RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;
      &lt;LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_below="@+id/LinearLayout01" android:visibility="invisible"&gt;
          &lt;RadioGroup android:id="@+id/RadioGroup01" android:layout_height="wrap_content" android:checkedButton="@+id/RB01" android:layout_width="fill_parent"&gt;
              &lt;RadioButton android:id="@+id/RB01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR01"/&gt;
              &lt;RadioButton android:id="@+id/RB02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR02"/&gt;
              &lt;RadioButton android:id="@+id/RB03" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR03"/&gt;
              &lt;RadioButton android:id="@+id/RB04" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR04"/&gt;
          &lt;/RadioGroup&gt;
      &lt;/LinearLayout&gt;
      &lt;/RelativeLayout&gt;
  </code></pre>