I used a bit google translator so the text may seem strange.
Android: 2.3.7
MDM= new MenuDrawerManager(this, MenuDrawer.MENU_DRAG_WINDOW);
MDM.setContentView(~empty FrameLayout, that will be a container in which
I will be add or replace different Fragments depending on
which menu item was clicked~);
MDM.setMenuView(~MenuScrollView from example application
with padding to left and right side,
which contains LinearLayout with menu items);
I'm using ActionBarSherlock, that placed, in this case, above fragment container.
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(~Custom view that consist from
custom implementation of ImageButton and standard TextView~);
Implementation of ImageButton overrides onMeasure to make button always square (regardless of the orientation of the screen) depending on ActionBar height:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = View.MeasureSpec.getSize(heightMeasureSpec);
~Here I call method from activity that contains the menu,
passing the new width of the button.
This method changes the width of the menu through call
MenuDraver.setMenuWidth with new width
computed to make right border of the button
(in menu opened state) located
exactly at right border of the screen, if the total screen width
less then some MAX_MENU_WIDTH constant.
There are actually a bit more complicated scheme,
but it does not matter.
The point is that on devices with a small
screen I need to change the width of the menu
when changed screen orientation.~
super.onMeasure(heightMeasureSpec, heightMeasureSpec);
}
Im manually handle screen orientation changes (android:configChanges="keyboardHidden|orientation|screenSize|locale").
MenuDraver.setMenuWidth correctly work on first use, but then, when screen orientation being changed, size of mMenuContainer is updates correctly, but its children, MenuScrollView , on its onSizeChanged method obtains incorrect, outdated (from previonsly orientation) size, and its padding displays incorrectly (skewed to one side).
I fixed it replacing this:
public void setMenuWidth(final int width) {
mMenuWidth = width;
mMenuWidthSet = true;
if (mDrawerState == STATE_OPEN || mDrawerState == STATE_OPENING) {
setOffsetPixels(mMenuWidth);
}
requestLayout();
invalidate();
}
With this:
public void setMenuWidth(final int width) {
mMenuWidth = width;
mMenuWidthSet = true;
if (mDrawerState == STATE_OPEN || mDrawerState == STATE_OPENING) {
setOffsetPixels(mMenuWidth);
}
post(new Runnable() {
public void run() {
requestLayout();
invalidate();
}
});
}
After these changes, it has become updating mMenuContainer childs properly.
Little off topic, possibly this:
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
final int offsetPixels = mOffsetPixels;
drawMenuOverlay(canvas, offsetPixels);
if (mDropShadowEnabled)
drawDropShadow(canvas, offsetPixels);
if (mArrowBitmap != null)
drawArrow(canvas, offsetPixels);
}
Will be a bit more effective in this form:
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
final int offsetPixels = mOffsetPixels;
if (mDrawerState != STATE_OPEN)
drawMenuOverlay(canvas, offsetPixels);
if (mDropShadowEnabled)
drawDropShadow(canvas, offsetPixels);
if (mArrowBitmap != null)
drawArrow(canvas, offsetPixels);
}