1717
1818import android .content .Context ;
1919import android .content .res .Configuration ;
20+ import android .content .res .TypedArray ;
2021import android .util .AttributeSet ;
2122import android .view .Gravity ;
2223import android .view .View ;
2526import android .view .accessibility .AccessibilityEvent ;
2627import android .widget .LinearLayout ;
2728
29+ import com .android .internal .R ;
30+
2831/**
2932 * @hide
3033 */
@@ -43,6 +46,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
4346 private int mMinCellSize ;
4447 private int mGeneratedItemPadding ;
4548 private int mMeasuredExtraWidth ;
49+ private int mMaxItemHeight ;
4650
4751 public ActionMenuView (Context context ) {
4852 this (context , null );
@@ -54,6 +58,11 @@ public ActionMenuView(Context context, AttributeSet attrs) {
5458 final float density = context .getResources ().getDisplayMetrics ().density ;
5559 mMinCellSize = (int ) (MIN_CELL_SIZE * density );
5660 mGeneratedItemPadding = (int ) (GENERATED_ITEM_PADDING * density );
61+
62+ TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .ActionBar ,
63+ R .attr .actionBarStyle , 0 );
64+ mMaxItemHeight = a .getDimensionPixelSize (R .styleable .ActionBar_height , 0 );
65+ a .recycle ();
5766 }
5867
5968 public void setPresenter (ActionMenuPresenter presenter ) {
@@ -116,6 +125,11 @@ private void onMeasureExactFormat(int widthMeasureSpec, int heightMeasureSpec) {
116125 final int widthPadding = getPaddingLeft () + getPaddingRight ();
117126 final int heightPadding = getPaddingTop () + getPaddingBottom ();
118127
128+ final int itemHeightSpec = heightMode == MeasureSpec .EXACTLY
129+ ? MeasureSpec .makeMeasureSpec (heightSize - heightPadding , MeasureSpec .EXACTLY )
130+ : MeasureSpec .makeMeasureSpec (
131+ Math .min (mMaxItemHeight , heightSize - heightPadding ), MeasureSpec .AT_MOST );
132+
119133 widthSize -= widthPadding ;
120134
121135 // Divide the view into cells.
@@ -167,7 +181,7 @@ private void onMeasureExactFormat(int widthMeasureSpec, int heightMeasureSpec) {
167181 final int cellsAvailable = lp .isOverflowButton ? 1 : cellsRemaining ;
168182
169183 final int cellsUsed = measureChildForCells (child , cellSize , cellsAvailable ,
170- heightMeasureSpec , heightPadding );
184+ itemHeightSpec , heightPadding );
171185
172186 maxCellsUsed = Math .max (maxCellsUsed , cellsUsed );
173187 if (lp .expandable ) expandableItemCount ++;
@@ -298,15 +312,15 @@ private void onMeasureExactFormat(int widthMeasureSpec, int heightMeasureSpec) {
298312
299313 // Remeasure any items that have had extra space allocated to them.
300314 if (needsExpansion ) {
301- int heightSpec = MeasureSpec .makeMeasureSpec (heightSize - heightPadding , heightMode );
302315 for (int i = 0 ; i < childCount ; i ++) {
303316 final View child = getChildAt (i );
304317 final LayoutParams lp = (LayoutParams ) child .getLayoutParams ();
305318
306319 if (!lp .expanded ) continue ;
307320
308321 final int width = lp .cellsUsed * cellSize + lp .extraPixels ;
309- child .measure (MeasureSpec .makeMeasureSpec (width , MeasureSpec .EXACTLY ), heightSpec );
322+ child .measure (MeasureSpec .makeMeasureSpec (width , MeasureSpec .EXACTLY ),
323+ itemHeightSpec );
310324 }
311325 }
312326
0 commit comments