diff options
| author | Kirill Grouchnikov <kirillg@google.com> | 2016-04-26 15:28:25 -0400 |
|---|---|---|
| committer | Kirill Grouchnikov <kirillg@google.com> | 2016-04-28 15:22:47 -0400 |
| commit | 9df0846498b2be2e03c487d0dba73c1d7c20f39c (patch) | |
| tree | 81f3869952648b80fb0e5ba84c9d4e60d614c574 /core/java/android/widget/LinearLayout.java | |
| parent | 03cc94955d0fc9653c08c1bbdd46bcbcbce299e0 (diff) | |
Aligning behavior of LinearLayout divider APIs
Consistency for:
* Early return on calling setter with the current state
* Calling setWillNotDraw when divider is configured with drawable
and visible
* Calling requestLayout to trigger a relayout pass
Also fix a bug that wouldn't show end divider when all non-GONE
children have 0 width/height.
Bug: 28398719
Bug: 28404367
Change-Id: I16796c74a52ac4c3041390c75add2ec3c33bea8b
Diffstat (limited to 'core/java/android/widget/LinearLayout.java')
| -rw-r--r-- | core/java/android/widget/LinearLayout.java | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java index f75b74bb9a14..3ced25359397 100644 --- a/core/java/android/widget/LinearLayout.java +++ b/core/java/android/widget/LinearLayout.java @@ -246,17 +246,28 @@ public class LinearLayout extends ViewGroup { } /** + * Returns <code>true</code> if this layout is currently configured to show at least one + * divider. + */ + private boolean isShowingDividers() { + return (mShowDividers != SHOW_DIVIDER_NONE) && (mDivider != null); + } + + /** * Set how dividers should be shown between items in this layout * * @param showDividers One or more of {@link #SHOW_DIVIDER_BEGINNING}, - * {@link #SHOW_DIVIDER_MIDDLE}, or {@link #SHOW_DIVIDER_END}, - * or {@link #SHOW_DIVIDER_NONE} to show no dividers. + * {@link #SHOW_DIVIDER_MIDDLE}, or {@link #SHOW_DIVIDER_END} + * to show dividers, or {@link #SHOW_DIVIDER_NONE} to show no dividers. */ public void setShowDividers(@DividerMode int showDividers) { - if (showDividers != mShowDividers) { - requestLayout(); + if (showDividers == mShowDividers) { + return; } mShowDividers = showDividers; + + setWillNotDraw(!isShowingDividers()); + requestLayout(); } @Override @@ -305,12 +316,15 @@ public class LinearLayout extends ViewGroup { mDividerWidth = 0; mDividerHeight = 0; } - setWillNotDraw(divider == null); + + setWillNotDraw(!isShowingDividers()); requestLayout(); } /** - * Set padding displayed on both ends of dividers. + * Set padding displayed on both ends of dividers. For a vertical layout, the padding is applied + * to left and right end of dividers. For a horizontal layout, the padding is applied to top and + * bottom end of dividers. * * @param padding Padding value in pixels that will be applied to each end * @@ -319,7 +333,15 @@ public class LinearLayout extends ViewGroup { * @see #getDividerPadding() */ public void setDividerPadding(int padding) { + if (padding == mDividerPadding) { + return; + } mDividerPadding = padding; + + if (isShowingDividers()) { + requestLayout(); + invalidate(); + } } /** @@ -711,6 +733,8 @@ public class LinearLayout extends ViewGroup { int largestChildHeight = Integer.MIN_VALUE; int consumedExcessSpace = 0; + int nonSkippedChildCount = 0; + // See how tall everyone is. Also remember max width. for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); @@ -724,6 +748,7 @@ public class LinearLayout extends ViewGroup { continue; } + nonSkippedChildCount++; if (hasDividerBeforeChildAt(i)) { mTotalLength += mDividerHeight; } @@ -825,7 +850,7 @@ public class LinearLayout extends ViewGroup { i += getChildrenSkipCount(child, i); } - if (mTotalLength > 0 && hasDividerBeforeChildAt(count)) { + if (nonSkippedChildCount > 0 && hasDividerBeforeChildAt(count)) { mTotalLength += mDividerHeight; } @@ -865,7 +890,6 @@ public class LinearLayout extends ViewGroup { // Reconcile our calculated size with the heightMeasureSpec int heightSizeAndState = resolveSizeAndState(heightSize, heightMeasureSpec, 0); heightSize = heightSizeAndState & MEASURED_SIZE_MASK; - // Either expand children with weight to take up available space or // shrink them if they extend beyond our current bounds. If we skipped // measurement on any children, we need to measure them now. @@ -1049,6 +1073,8 @@ public class LinearLayout extends ViewGroup { int largestChildWidth = Integer.MIN_VALUE; int usedExcessSpace = 0; + int nonSkippedChildCount = 0; + // See how wide everyone is. Also remember max height. for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); @@ -1062,6 +1088,7 @@ public class LinearLayout extends ViewGroup { continue; } + nonSkippedChildCount++; if (hasDividerBeforeChildAt(i)) { mTotalLength += mDividerWidth; } @@ -1184,7 +1211,7 @@ public class LinearLayout extends ViewGroup { i += getChildrenSkipCount(child, i); } - if (mTotalLength > 0 && hasDividerBeforeChildAt(count)) { + if (nonSkippedChildCount > 0 && hasDividerBeforeChildAt(count)) { mTotalLength += mDividerWidth; } |
