summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2010-02-25 11:01:01 -0800
committerRomain Guy <romainguy@android.com>2010-02-25 11:01:01 -0800
commitc352090c49b50a70aaddeb428bd5e27f7419884f (patch)
treecf8e24729e8874df091fb8c43a1238fbd440e12a /core
parent2299a553bc35ecc15dab0e36732b126e1eb8d446 (diff)
downloadframeworks_base-c352090c49b50a70aaddeb428bd5e27f7419884f.zip
frameworks_base-c352090c49b50a70aaddeb428bd5e27f7419884f.tar.gz
frameworks_base-c352090c49b50a70aaddeb428bd5e27f7419884f.tar.bz2
Correctly handle negative margins in horizontal linear layouts.
When LinearLayout is measured in EXACTLY mode, we handle the negative margins a bit differently. This is to support the use case of the current tab design.
Diffstat (limited to 'core')
-rw-r--r--core/java/android/widget/LinearLayout.java40
1 files changed, 33 insertions, 7 deletions
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index 4bd3a82..bd07e1f 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -632,6 +632,8 @@ public class LinearLayout extends ViewGroup {
final boolean baselineAligned = mBaselineAligned;
final boolean useLargestChild = mUseLargestChild;
+
+ final boolean isExactly = widthMode == MeasureSpec.EXACTLY;
int largestChildWidth = Integer.MIN_VALUE;
@@ -658,7 +660,13 @@ public class LinearLayout extends ViewGroup {
// Optimization: don't bother measuring children who are going to use
// leftover space. These views will get measured again down below if
// there is any leftover space.
- mTotalLength += lp.leftMargin + lp.rightMargin;
+ if (isExactly) {
+ mTotalLength += lp.leftMargin + lp.rightMargin;
+ } else {
+ final int totalLength = mTotalLength;
+ mTotalLength = Math.max(totalLength, totalLength +
+ lp.leftMargin + lp.rightMargin);
+ }
// Baseline alignment requires to measure widgets to obtain the
// baseline offset (in particular for TextViews). The following
@@ -694,8 +702,14 @@ public class LinearLayout extends ViewGroup {
}
final int childWidth = child.getMeasuredWidth();
- mTotalLength += childWidth + lp.leftMargin + lp.rightMargin +
- getNextLocationOffset(child);
+ if (isExactly) {
+ mTotalLength += childWidth + lp.leftMargin + lp.rightMargin +
+ getNextLocationOffset(child);
+ } else {
+ final int totalLength = mTotalLength;
+ mTotalLength = Math.max(totalLength, totalLength + childWidth + lp.leftMargin +
+ lp.rightMargin + getNextLocationOffset(child));
+ }
if (useLargestChild) {
largestChildWidth = Math.max(childWidth, largestChildWidth);
@@ -780,8 +794,14 @@ public class LinearLayout extends ViewGroup {
final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)
child.getLayoutParams();
- mTotalLength += largestChildWidth + lp.leftMargin + lp.rightMargin +
- getNextLocationOffset(child);
+ if (isExactly) {
+ mTotalLength += largestChildWidth + lp.leftMargin + lp.rightMargin +
+ getNextLocationOffset(child);
+ } else {
+ final int totalLength = mTotalLength;
+ mTotalLength = Math.max(totalLength, totalLength + largestChildWidth +
+ lp.leftMargin + lp.rightMargin + getNextLocationOffset(child));
+ }
}
}
@@ -851,8 +871,14 @@ public class LinearLayout extends ViewGroup {
}
}
- mTotalLength += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin +
- getNextLocationOffset(child);
+ if (isExactly) {
+ mTotalLength += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin +
+ getNextLocationOffset(child);
+ } else {
+ final int totalLength = mTotalLength;
+ mTotalLength = Math.max(totalLength, totalLength + child.getMeasuredWidth() +
+ lp.leftMargin + lp.rightMargin + getNextLocationOffset(child));
+ }
boolean matchHeightLocally = heightMode != MeasureSpec.EXACTLY &&
lp.height == LayoutParams.MATCH_PARENT;