diff options
| author | Fabrice Di Meglio <fdimeglio@google.com> | 2013-06-18 23:55:01 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-06-18 23:55:01 +0000 |
| commit | 1cc0a6514f3f1865d93bdf12cd01002ab4099ed0 (patch) | |
| tree | 21c204a2691a23d3f23b66886bc217be808e712b /core/java | |
| parent | 9dafebb8172d767d640c526d717eaef6a52167f3 (diff) | |
| parent | f2fb76cc23e18f7b15f7244e6352d024b5008f38 (diff) | |
Merge "Fix potential NPE if there is no child in HorizontalScrollView"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/widget/HorizontalScrollView.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java index f0d80e6b2d0a..d114b7660d22 100644 --- a/core/java/android/widget/HorizontalScrollView.java +++ b/core/java/android/widget/HorizontalScrollView.java @@ -1457,14 +1457,22 @@ public class HorizontalScrollView extends FrameLayout { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { - // There is only one child - final View child = getChildAt(0); - final int childWidth = child.getMeasuredWidth(); - final LayoutParams childParams = (LayoutParams) child.getLayoutParams(); + int childWidth = 0; + int childMargins = 0; + + if (getChildCount() > 0) { + childWidth = getChildAt(0).getMeasuredWidth(); + LayoutParams childParams = (LayoutParams) getChildAt(0).getLayoutParams(); + childMargins = childParams.leftMargin + childParams.rightMargin; + } + final int available = r - l - getPaddingLeftWithForeground() - - getPaddingRightWithForeground() - childParams.leftMargin - childParams.rightMargin; + getPaddingRightWithForeground() - childMargins; + final boolean forceLeftGravity = (childWidth > available); + layoutChildren(l, t, r, b, forceLeftGravity); + mIsLayoutDirty = false; // Give a child focus if it needs it if (mChildToScrollTo != null && isViewDescendantOf(mChildToScrollTo, this)) { |
