Cheesebaron.HorizontalPager.HorizontalPager.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)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            int width = MeasureSpec.GetSize(widthMeasureSpec);
            MeasureSpecMode widthMode = MeasureSpec.GetMode(widthMeasureSpec);
            if (widthMode != MeasureSpecMode.Exactly)
            {
                throw new Exception("ViewSwithcer can only be used in EXACTLY mode.");
            }

            MeasureSpecMode heightMode = MeasureSpec.GetMode(heightMeasureSpec);
            if (heightMode != MeasureSpecMode.Exactly)
            {
                throw new Exception("ViewSwithcer can only be used in EXACTLY mode.");
            }

            int count = this.ChildCount;
            for (int i = 0; i < count; i++)
                GetChildAt(i).Measure(widthMeasureSpec, heightMeasureSpec);

            if (mFirstLayout)
            {
                ScrollTo(mCurrentScreen * width, 0);
                mFirstLayout = false;
            }
            else if (width != mLastSeenLayoutWidth)
            {
                Display display = ((IWindowManager)Context.GetSystemService(Context.WindowService)).DefaultDisplay;
                int displayWidth = display.Width;

                mNextScreen = Math.Max(0, Math.Min(mCurrentScreen, this.ChildCount - 1));
                int newX = mNextScreen * displayWidth;
                int delta = newX - this.ScrollX;

                mScroller.StartScroll(this.ScrollX, 0, delta, 0);
            }

            mLastSeenLayoutWidth = width;
        }