Cheesebaron.SlidingUpPanel.SlidingUpPanelLayout.OnMeasure C# (CSharp) Method

OnMeasure() protected method

protected OnMeasure ( int widthMeasureSpec, int heightMeasureSpec ) : void
widthMeasureSpec int
heightMeasureSpec int
return void
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            var widthMode = MeasureSpec.GetMode(widthMeasureSpec);
            var widthSize = MeasureSpec.GetSize(widthMeasureSpec);
            var heightMode = MeasureSpec.GetMode(heightMeasureSpec);
            var heightSize = MeasureSpec.GetSize(heightMeasureSpec);

            if (widthMode != MeasureSpecMode.Exactly)
                throw new InvalidOperationException("Width must have an exact value or match_parent");
            if (heightMode != MeasureSpecMode.Exactly)
                throw new InvalidOperationException("Height must have an exact value or match_parent");

            var layoutHeight = heightSize - PaddingTop - PaddingBottom;
            var panelHeight = _panelHeight;

            if (ChildCount > 2)
                Log.Error(Tag, "OnMeasure: More than two child views are not supported.");
            else
                panelHeight = 0;

            _slideableView = null;
            _canSlide = false;

            for (var i = 0; i < ChildCount; i++)
            {
                var child = GetChildAt(i);
                var lp = (LayoutParams) child.LayoutParameters;

                var height = layoutHeight;
                if (child.Visibility == ViewStates.Gone)
                {
                    lp.DimWhenOffset = false;
                    continue;
                }

                if (i == 1)
                {
                    lp.Slideable = true;
                    lp.DimWhenOffset = true;
                    _slideableView = child;
                    _canSlide = true;
                }
                else
                {
                    if (!OverlayContent)
                        height -= panelHeight;
                }

                int childWidthSpec;
                if (lp.Width == ViewGroup.LayoutParams.WrapContent)
                    childWidthSpec = MeasureSpec.MakeMeasureSpec(widthSize, MeasureSpecMode.AtMost);
                else if (lp.Width == ViewGroup.LayoutParams.MatchParent)
                    childWidthSpec = MeasureSpec.MakeMeasureSpec(widthSize, MeasureSpecMode.Exactly);
                else
                    childWidthSpec = MeasureSpec.MakeMeasureSpec(lp.Width, MeasureSpecMode.Exactly);

                int childHeightSpec;
                if (lp.Height == ViewGroup.LayoutParams.WrapContent)
                    childHeightSpec = MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.AtMost);
                else if (lp.Height == ViewGroup.LayoutParams.MatchParent)
                    childHeightSpec = MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly);
                else
                    childHeightSpec = MeasureSpec.MakeMeasureSpec(lp.Height, MeasureSpecMode.Exactly);

                child.Measure(childWidthSpec, childHeightSpec);
            }
            SetMeasuredDimension(widthSize, heightSize);
        }