31
31
import android .support .v7 .view .menu .MenuItemImpl ;
32
32
import android .support .v7 .view .menu .MenuView ;
33
33
import android .util .AttributeSet ;
34
+ import android .view .Gravity ;
34
35
import android .view .View ;
35
36
import android .view .ViewGroup ;
37
+ import android .widget .FrameLayout ;
36
38
37
39
/** @hide For internal use only. */
38
40
@ RestrictTo (LIBRARY_GROUP )
39
41
public class BottomNavigationMenuView extends ViewGroup implements MenuView {
40
42
private final int mInactiveItemMaxWidth ;
41
43
private final int mInactiveItemMinWidth ;
44
+ private final int mInactiveItemMaxHeight ;
45
+ private final int mInactiveItemMinHeight ;
42
46
private final int mActiveItemMaxWidth ;
43
47
private final int mActiveItemMaxHeight ;
44
48
private final int mItemWidth ;
@@ -72,6 +76,10 @@ public BottomNavigationMenuView(Context context, AttributeSet attrs) {
72
76
res .getDimensionPixelSize (R .dimen .design_bottom_navigation_item_max_width );
73
77
mInactiveItemMinWidth =
74
78
res .getDimensionPixelSize (R .dimen .design_bottom_navigation_item_min_width );
79
+ mInactiveItemMaxHeight =
80
+ res .getDimensionPixelSize (R .dimen .design_bottom_navigation_item_max_height );
81
+ mInactiveItemMinHeight =
82
+ res .getDimensionPixelSize (R .dimen .design_bottom_navigation_item_min_height );
75
83
mActiveItemMaxWidth =
76
84
res .getDimensionPixelSize (R .dimen .design_bottom_navigation_active_item_max_width );
77
85
mActiveItemMaxHeight =
@@ -112,7 +120,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
112
120
113
121
final int heightSpec = MeasureSpec .makeMeasureSpec (mItemHeight , MeasureSpec .EXACTLY );
114
122
115
- if (mShiftingMode ) {
123
+ if (mTabletMode ) {
124
+ measureTabletMode (heightMeasureSpec );
125
+ return ;
126
+ } else if (mShiftingMode ) {
116
127
final int inactiveCount = count - 1 ;
117
128
final int activeMaxAvailable = width - inactiveCount * mInactiveItemMinWidth ;
118
129
final int activeWidth = Math .min (activeMaxAvailable , mActiveItemMaxWidth );
@@ -126,9 +137,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
126
137
extra --;
127
138
}
128
139
}
129
- } else if (mTabletMode ) {
130
- measureTabletMode (heightMeasureSpec );
131
- return ;
132
140
} else {
133
141
final int maxAvailable = width / (count == 0 ? 1 : count );
134
142
final int childWidth = Math .min (maxAvailable , mActiveItemMaxWidth );
@@ -166,14 +174,30 @@ private void measureTabletMode(int heightMeasureSpec) {
166
174
167
175
final int widthSpec = MeasureSpec .makeMeasureSpec (mItemWidth , MeasureSpec .EXACTLY );
168
176
169
- final int maxAvailable = height / (count == 0 ? 1 : count );
170
- final int childHeight = Math .min (maxAvailable , mActiveItemMaxHeight );
171
- int extra = height - childHeight * count ;
172
- for (int i = 0 ; i < count ; i ++) {
173
- mTempChildSizes [i ] = childHeight ;
174
- if (extra > 0 ) {
175
- mTempChildSizes [i ]++;
176
- extra --;
177
+ if (mShiftingMode ) {
178
+ final int inactiveCount = count - 1 ;
179
+ final int activeMaxAvailable = height - inactiveCount * mInactiveItemMinHeight ;
180
+ final int activeHeight = Math .min (activeMaxAvailable , mActiveItemMaxHeight );
181
+ final int inactiveMaxAvailable = (height - activeHeight ) / inactiveCount ;
182
+ final int inactiveHeight = Math .min (inactiveMaxAvailable , mInactiveItemMaxHeight );
183
+ int extra = height - activeHeight - inactiveHeight * inactiveCount ;
184
+ for (int i = 0 ; i < count ; i ++) {
185
+ mTempChildSizes [i ] = (i == mActiveButton ) ? activeHeight : inactiveHeight ;
186
+ if (extra > 0 ) {
187
+ mTempChildSizes [i ]++;
188
+ extra --;
189
+ }
190
+ }
191
+ } else {
192
+ final int maxAvailable = height / (count == 0 ? 1 : count );
193
+ final int childHeight = Math .min (maxAvailable , mActiveItemMaxHeight );
194
+ int extra = height - childHeight * count ;
195
+ for (int i = 0 ; i < count ; i ++) {
196
+ mTempChildSizes [i ] = childHeight ;
197
+ if (extra > 0 ) {
198
+ mTempChildSizes [i ]++;
199
+ extra --;
200
+ }
177
201
}
178
202
}
179
203
@@ -334,6 +358,11 @@ public void buildMenuView() {
334
358
}
335
359
mButtons = new BottomNavigationItemView [mMenu .size ()];
336
360
mShiftingMode = mMenu .size () > 3 ;
361
+ if (mTabletMode ) {
362
+ FrameLayout .LayoutParams params = (FrameLayout .LayoutParams ) getLayoutParams ();
363
+ params .gravity = mShiftingMode ? Gravity .CENTER : Gravity .TOP ;
364
+ setLayoutParams (params );
365
+ }
337
366
for (int i = 0 ; i < mMenu .size (); i ++) {
338
367
mPresenter .setUpdateSuspended (true );
339
368
mMenu .getItem (i ).setCheckable (true );
0 commit comments