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
This commit is contained in:
Adam Powell
2012-08-08 15:59:12 -07:00
parent a56d9cecee
commit 6322af54cf
2 changed files with 10 additions and 7 deletions

View File

@@ -985,9 +985,13 @@ public class ProgressBar extends View {
}
private void updateDrawableBounds(int w, int h) {
// onDraw will translate the canvas so we draw starting at 0,0
int right = w - mPaddingRight - mPaddingLeft;
int bottom = h - mPaddingBottom - mPaddingTop;
// onDraw will translate the canvas so we draw starting at 0,0.
// Subtract out padding for the purposes of the calculations below.
w -= mPaddingRight + mPaddingLeft;
h -= mPaddingTop + mPaddingBottom;
int right = w;
int bottom = h;
int top = 0;
int left = 0;

View File

@@ -856,6 +856,7 @@ public class ActionBarView extends AbsActionBarView {
final int paddingRight = getPaddingRight();
final int height = maxHeight - verticalPadding;
final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
final int exactHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
int availableWidth = contentWidth - paddingLeft - paddingRight;
int leftOfCenter = availableWidth / 2;
@@ -871,16 +872,14 @@ public class ActionBarView extends AbsActionBarView {
} else {
homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
}
homeLayout.measure(homeWidthSpec,
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
homeLayout.measure(homeWidthSpec, exactHeightSpec);
final int homeWidth = homeLayout.getMeasuredWidth() + homeLayout.getStartOffset();
availableWidth = Math.max(0, availableWidth - homeWidth);
leftOfCenter = Math.max(0, availableWidth - homeWidth);
}
if (mMenuView != null && mMenuView.getParent() == this) {
availableWidth = measureChildView(mMenuView, availableWidth,
childSpecHeight, 0);
availableWidth = measureChildView(mMenuView, availableWidth, exactHeightSpec, 0);
rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth());
}