title: RelativeLayout: align view to child of sibling viewgroup
body: <p>I'm trying to make a tab bar in android using a RelativeLayout and a RadioGroup that has an indicator which will slide to indicate the active RadioButton within the RadioGroup.</p>
  
  <p>These are customized radio buttons that are effectively rectangles with an icon over text, all contents centered, which uses a custom state-selector for the background.</p>
  
  <p>Here's my current hierarchy:</p>
  
  <pre><code>&lt;RelativeLayout&gt;       // Main view of the tab bar
    &lt;RadioGroup&gt;         // The buttons
      &lt;RadioButton /&gt;
      &lt;RadioButton /&gt;
      &lt;RadioButton /&gt;
    &lt;/RadioGroup&gt;
    &lt;ImageView /&gt;        // The indicator
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>The idea I had was when a radio button was clicked, I would align the indicator to the top &amp; bottom of the selected radio button (and animate it).  However, It seems that <code>layout_align&lt;Edge&gt;</code> only works with sibling elements, not with members of another view group, i.e. I can align to the RadioGroup itself, but not to a RadioButton inside it.</p>
  
  <p>I thought of putting the indicator as a member of the RadioGroup, but since RadioGroup is an extension of LinearLayout, there doesn't seem to be a way to place it at the edge of a given RadioButton.</p>
  
  <p>Can anyone think of how I might solve this issue?  Or perhaps there's a better solution than my animate-align-to-button technique?</p>
  
  <p><strong>UPDATE</strong>
  With @superjos help, I managed to work this out fairly well.  </p>
  
  <p>I had to give each button a known height instead of using <code>wrap_content</code> (not ideal, but for this project it should probably work fine). Make the indicator height match that of the buttons. Make sure the RadioGroup is set to wrap content and be centered vertically in the parent view. Set indicator to <code>alignTop</code> and <code>toRightOf</code> the RadioGroup.  Then, for the button click listener: </p>
  
  <pre><code>int prevY, newY;
  int prevButtonIndex, newButtonIndex;
  
  public void moveIndicator(button, indicator, index) {
    prevY = newY;
    newY = prevY + (index - prevButtonIndex) * button.getHeight();
    TranslateAnimation animation = new TranslateAnimation(0, 0, prevY, newY);
    animation.setDuration(500);
    animation.setFillAfter(true); // stay at final animation position
    indicator.setAnimation();
    animation.start();
  }
  </code></pre>