From 51b5caf902a6bedc016096abc7ef9e5d0e1a68c7 Mon Sep 17 00:00:00 2001 From: Yigit Boyar Date: Fri, 27 May 2016 15:18:54 -0700 Subject: [PATCH] Invalidate child bounds when AbsListView bounds change This CL fixes a bug in AbsListView where it was not invalidating children's bounds when AbsListView's bounds change. This was triggering bugs where if you set padding on a list view, it would not resize its children. Bug: 28800232 Change-Id: I81a4e9ea234c395de80efea5ef5e47a71cb95136 --- core/java/android/widget/AbsListView.java | 40 ++++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index 28ade80a260e1..b331be72b4cf1 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -2675,18 +2675,48 @@ public abstract class AbsListView extends AdapterView implements Te return (mGroupFlags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK ? 0 : mPaddingBottom; } + /** + * @hide + */ + @Override + protected void internalSetPadding(int left, int top, int right, int bottom) { + super.internalSetPadding(left, top, right, bottom); + if (isLayoutRequested()) { + handleBoundsChange(); + } + } + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { - if (getChildCount() > 0) { - mDataChanged = true; - rememberSyncState(); - } - + handleBoundsChange(); if (mFastScroll != null) { mFastScroll.onSizeChanged(w, h, oldw, oldh); } } + /** + * Called when bounds of the AbsListView are changed. AbsListView marks data set as changed + * and force layouts all children that don't have exact measure specs. + *

+ * This invalidation is necessary, otherwise, AbsListView may think the children are valid and + * fail to relayout them properly to accommodate for new bounds. + */ + void handleBoundsChange() { + final int childCount = getChildCount(); + if (childCount > 0) { + mDataChanged = true; + rememberSyncState(); + for (int i = 0; i < childCount; i++) { + final View child = getChildAt(i); + final ViewGroup.LayoutParams lp = child.getLayoutParams(); + // force layout child unless it has exact specs + if (lp == null || lp.width < 1 || lp.height < 1) { + child.forceLayout(); + } + } + } + } + /** * @return True if the current touch mode requires that we draw the selector in the pressed * state.