Cheesebaron.ParallaxScrollView.ParallaxScrollView.OnLayout C# (CSharp) Method

OnLayout() protected method

protected OnLayout ( bool changed, int l, int t, int r, int b ) : void
changed bool
l int
t int
r int
b int
return void
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            var parentLeft = PaddingLeft;
            var parentRight = r - l - PaddingRight;
            var parentTop = PaddingTop;
            var parentBottom = b - t - PaddingBottom;

            if (_scrollView != null && _scrollView.Visibility != ViewStates.Gone)
            {
                var lp = (FrameLayout.LayoutParams) _scrollView.LayoutParameters;
                var width = _scrollView.MeasuredWidth;
                var height = _scrollView.MeasuredHeight;

                int childLeft;
                int childTop;

                var gravity = lp.Gravity;
                if (gravity == GravityFlags.NoGravity)
                    gravity = DefaultChildGravity;

                var horizontalGravity = gravity & GravityFlags.HorizontalGravityMask;
                var verticalGravity = gravity & GravityFlags.VerticalGravityMask;

                switch (horizontalGravity)
                {
                    case GravityFlags.Left:
                        childLeft = parentLeft - lp.LeftMargin;
                        break;
                    case GravityFlags.CenterHorizontal:
                        childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.LeftMargin - lp.RightMargin;
                        break;
                    case GravityFlags.Right:
                        childLeft = parentRight - width - lp.RightMargin;
                        break;
                    default:
                        childLeft = parentLeft + lp.LeftMargin;
                        break;
                }

                switch (verticalGravity)
                {
                    case GravityFlags.Top:
                        childTop = parentTop + lp.TopMargin;
                        break;
                    case GravityFlags.CenterVertical:
                        childTop = parentTop + (parentBottom - parentTop - height) / 2 + lp.TopMargin - lp.BottomMargin;
                        break;
                    case GravityFlags.Bottom:
                        childTop = parentBottom - height - lp.BottomMargin;
                        break;
                    default:
                        childTop = parentTop + lp.TopMargin;
                        break;
                }

                _scrollView.Layout(childLeft, childTop, childLeft + width, childTop + height);
            }

            if (_background != null && _scrollView != null)
            {
                var scrollYCenterOffset = -_scrollView.ScrollY;
                var offset = (int) (scrollYCenterOffset * _scrollDiff);
                _background.Layout(Left, offset, _backgroundRight, offset + _backgroundBottom);
            }
        }