Skip to content

Commit 6322af5

Browse files
committed
Fix indeterminate ProgressBars with weird sizes and padding; optimize
ActionBar measurement Fix a bug where preserved aspect ratios in ProgressBar indeterminate drawables were causing drawable bounds to be calculated incorrectly when the ProgressBar had padding specified. Measure the ActionBar menu view's height with EXACT measure mode, preventing an extra measure pass to match child heights for some cases. Change-Id: I8c4678662a015b57ba2686d5b5c5fc27d4ef8d36
1 parent a56d9ce commit 6322af5

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

core/java/android/widget/ProgressBar.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,13 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
985985
}
986986

987987
private void updateDrawableBounds(int w, int h) {
988-
// onDraw will translate the canvas so we draw starting at 0,0
989-
int right = w - mPaddingRight - mPaddingLeft;
990-
int bottom = h - mPaddingBottom - mPaddingTop;
988+
// onDraw will translate the canvas so we draw starting at 0,0.
989+
// Subtract out padding for the purposes of the calculations below.
990+
w -= mPaddingRight + mPaddingLeft;
991+
h -= mPaddingTop + mPaddingBottom;
992+
993+
int right = w;
994+
int bottom = h;
991995
int top = 0;
992996
int left = 0;
993997

core/java/com/android/internal/widget/ActionBarView.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
856856
final int paddingRight = getPaddingRight();
857857
final int height = maxHeight - verticalPadding;
858858
final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
859+
final int exactHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
859860

860861
int availableWidth = contentWidth - paddingLeft - paddingRight;
861862
int leftOfCenter = availableWidth / 2;
@@ -871,16 +872,14 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
871872
} else {
872873
homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
873874
}
874-
homeLayout.measure(homeWidthSpec,
875-
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
875+
homeLayout.measure(homeWidthSpec, exactHeightSpec);
876876
final int homeWidth = homeLayout.getMeasuredWidth() + homeLayout.getStartOffset();
877877
availableWidth = Math.max(0, availableWidth - homeWidth);
878878
leftOfCenter = Math.max(0, availableWidth - homeWidth);
879879
}
880880

881881
if (mMenuView != null && mMenuView.getParent() == this) {
882-
availableWidth = measureChildView(mMenuView, availableWidth,
883-
childSpecHeight, 0);
882+
availableWidth = measureChildView(mMenuView, availableWidth, exactHeightSpec, 0);
884883
rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth());
885884
}
886885

0 commit comments

Comments
 (0)