@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int buttonsHorizontalCenter = mLabelsPosition == LABELS_POSITION_LEFT ? r - l - mMaxButtonWidth / 2 - getPaddingRight() : mMaxButtonWidth / 2 + getPaddingLeft(); boolean openUp = mOpenDirection == OPEN_UP; int menuButtonTop = openUp ? b - t - mMenuButton.getMeasuredHeight() - getPaddingBottom() : getPaddingTop(); int menuButtonLeft = buttonsHorizontalCenter - mMenuButton.getMeasuredWidth() / 2; mMenuButton.layout( menuButtonLeft, menuButtonTop, menuButtonLeft + mMenuButton.getMeasuredWidth(), menuButtonTop + mMenuButton.getMeasuredHeight()); int imageLeft = buttonsHorizontalCenter - mImageToggle.getMeasuredWidth() / 2; int imageTop = menuButtonTop + mMenuButton.getMeasuredHeight() / 2 - mImageToggle.getMeasuredHeight() / 2; mImageToggle.layout( imageLeft, imageTop, imageLeft + mImageToggle.getMeasuredWidth(), imageTop + mImageToggle.getMeasuredHeight()); int nextY = openUp ? menuButtonTop - mButtonSpacing : menuButtonTop + mMenuButton.getMeasuredHeight() + mButtonSpacing; for (int i = mButtonsCount - 1; i >= 0; i--) { View child = getChildAt(i); if (child == mImageToggle) continue; FloatingActionButton fab = (FloatingActionButton) child; if (fab == mMenuButton || fab.getVisibility() == GONE) continue; int childX = buttonsHorizontalCenter - fab.getMeasuredWidth() / 2; int childY = openUp ? nextY - fab.getMeasuredHeight() : nextY; fab.layout(childX, childY, childX + fab.getMeasuredWidth(), childY + fab.getMeasuredHeight()); if (!mMenuOpened) { fab.hide(false); } View label = (View) fab.getTag(R.id.fab_label); if (label != null) { int labelsOffset = fab.getMeasuredWidth() / 2 + mLabelsMargin; int labelXNearButton = mLabelsPosition == LABELS_POSITION_LEFT ? buttonsHorizontalCenter - labelsOffset : buttonsHorizontalCenter + labelsOffset; int labelXAwayFromButton = mLabelsPosition == LABELS_POSITION_LEFT ? labelXNearButton - label.getMeasuredWidth() : labelXNearButton + label.getMeasuredWidth(); int labelLeft = mLabelsPosition == LABELS_POSITION_LEFT ? labelXAwayFromButton : labelXNearButton; int labelRight = mLabelsPosition == LABELS_POSITION_LEFT ? labelXNearButton : labelXAwayFromButton; int labelTop = childY - mLabelsVerticalOffset + (fab.getMeasuredHeight() - label.getMeasuredHeight()) / 2; label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight()); if (!mMenuOpened) { label.setVisibility(INVISIBLE); } } nextY = openUp ? childY - mButtonSpacing : childY + child.getMeasuredHeight() + mButtonSpacing; } }