Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cc0a651 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio Committed by Android (Google) Code Review
Browse files

Merge "Fix potential NPE if there is no child in HorizontalScrollView"

parents 9dafebb8 f2fb76cc
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -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)) {