title: Positioning items relative to the ActionBar in Android
body: <p>I used to have an Activity that would use no ActionBar. The layout is a <code>RelativeLayout</code> with width and height simply matching the parent. It allowed users to drag around buttons using <a href="https://stackoverflow.com/questions/10073304/how-can-i-drag-and-drop-views-within-android-relativelayout/10075146#10075146">parts of this code</a> in the <code>onTouch</code> event:</p>
  
  <pre><code>MarginLayoutParams marginParams = new MarginLayoutParams(v.getLayoutParams());
  int left = (int) event.getRawX() - (v.getWidth() / 2);
  int top  = (int) event.getRawY() - (v.getHeight());
  marginParams.setMargins(left, top, 0, 0);
  RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
  v.setLayoutParams(layoutParams);
  </code></pre>
  
  <p>All dandy—the button moves just below the finger and is placed correctly at the position on screen. Now, however, I enabled the ActionBar, and suddenly when clicked, the button moves ~30 pixels <em>below</em> the finger. To illustrate this behavior, here's what I used to have (on the left) and what happens right now (on the right):</p>
  
  <p><img src="https://i.stack.imgur.com/KDvpA.png" alt=""></p>
  
  <p>I assume this is because the ActionBar now displaces everything by its own height. Of course, I do not want this to happen, or at least correct this, so:</p>
  
  <ul>
  <li><p>How can I shift the placement in <code>setMargins()</code> according to the actual size of the ActionBar without using a hardcoded value?</p></li>
  <li><p>How can I prevent the ActionBar from shifting everything in the first place? Put differently, how can I ensure my button is placed relative to the ActionBar's bottom line and directly where the finger points?</p></li>
  </ul>
  
  <p>This is what I want:</p>
  
  <p><img src="https://i.stack.imgur.com/Qs7YL.png" alt=""></p>