Search code examples
androidactionbarsherlockandroid-actionbar

ActionbarSherlock getting Actionbar size


I'm using ActionbarSherlock 4.3.1 for compatibility to API 8. I use an overlay Actionbar:

public void onCreate(Bundle savedInstanceState) {               
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    setContentView(R.layout.activity_main);
...

I have an ImageView that fills the entire screen, including under the Actionbar (which is semi-transparent, like Google Maps). I use a RelativeLayout for drawing a button overlay on top of the ImageView. The RelativeLayout is offset vertically by the Actionbar size using android:layout_marginTop="?attr/actionBarSize" to that the top row of buttons appear just beneath the Actionbar.

The vertical offset works great on ICS and on, but not for Gingerbread (haven't tested HC or Froyo), where the buttons (which should appear just vertically below below the Actionbar) are covered up by the Actionbar and not vertically shifted downward.


Solution

  • It turns out the RelativeLayout must set android:layout_gravity="top" to make layout_marginTop work.