Merge "Fix bug #7112174 ActionMenuView should be aware of layout direction" into jb-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b250e94fdc
@@ -400,6 +400,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
|
||||
int nonOverflowCount = 0;
|
||||
int widthRemaining = right - left - getPaddingRight() - getPaddingLeft();
|
||||
boolean hasOverflow = false;
|
||||
final boolean isLayoutRtl = isLayoutRtl();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View v = getChildAt(i);
|
||||
if (v.getVisibility() == GONE) {
|
||||
@@ -414,8 +415,15 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
|
||||
}
|
||||
|
||||
int height = v.getMeasuredHeight();
|
||||
int r = getWidth() - getPaddingRight() - p.rightMargin;
|
||||
int l = r - overflowWidth;
|
||||
int r;
|
||||
int l;
|
||||
if (isLayoutRtl) {
|
||||
l = getPaddingLeft() + p.leftMargin;
|
||||
r = l + overflowWidth;
|
||||
} else {
|
||||
r = getWidth() - getPaddingRight() - p.rightMargin;
|
||||
l = r - overflowWidth;
|
||||
}
|
||||
int t = midVertical - (height / 2);
|
||||
int b = t + height;
|
||||
v.layout(l, t, r, b);
|
||||
@@ -448,20 +456,38 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
|
||||
final int spacerCount = nonOverflowCount - (hasOverflow ? 0 : 1);
|
||||
final int spacerSize = Math.max(0, spacerCount > 0 ? widthRemaining / spacerCount : 0);
|
||||
|
||||
int startLeft = getPaddingLeft();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View v = getChildAt(i);
|
||||
final LayoutParams lp = (LayoutParams) v.getLayoutParams();
|
||||
if (v.getVisibility() == GONE || lp.isOverflowButton) {
|
||||
continue;
|
||||
}
|
||||
if (isLayoutRtl) {
|
||||
int startRight = getWidth() - getPaddingRight();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View v = getChildAt(i);
|
||||
final LayoutParams lp = (LayoutParams) v.getLayoutParams();
|
||||
if (v.getVisibility() == GONE || lp.isOverflowButton) {
|
||||
continue;
|
||||
}
|
||||
|
||||
startLeft += lp.leftMargin;
|
||||
int width = v.getMeasuredWidth();
|
||||
int height = v.getMeasuredHeight();
|
||||
int t = midVertical - height / 2;
|
||||
v.layout(startLeft, t, startLeft + width, t + height);
|
||||
startLeft += width + lp.rightMargin + spacerSize;
|
||||
startRight -= lp.rightMargin;
|
||||
int width = v.getMeasuredWidth();
|
||||
int height = v.getMeasuredHeight();
|
||||
int t = midVertical - height / 2;
|
||||
v.layout(startRight - width, t, startRight, t + height);
|
||||
startRight -= width + lp.leftMargin + spacerSize;
|
||||
}
|
||||
} else {
|
||||
int startLeft = getPaddingLeft();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View v = getChildAt(i);
|
||||
final LayoutParams lp = (LayoutParams) v.getLayoutParams();
|
||||
if (v.getVisibility() == GONE || lp.isOverflowButton) {
|
||||
continue;
|
||||
}
|
||||
|
||||
startLeft += lp.leftMargin;
|
||||
int width = v.getMeasuredWidth();
|
||||
int height = v.getMeasuredHeight();
|
||||
int t = midVertical - height / 2;
|
||||
v.layout(startLeft, t, startLeft + width, t + height);
|
||||
startLeft += width + lp.rightMargin + spacerSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user