コード例 #1
0
        void SetLayout()
        {
            Control.Measure(AT_MOST, AT_MOST);
            Control.Measure(AT_MOST,
                            MeasureSpec.MakeMeasureSpec(Control.MeasuredHeight + 200, Android.Views.MeasureSpecMode.Exactly));
            Control.Layout(0, 0, Control.MeasuredWidth, Control.MeasuredHeight);

            Measure(MeasureSpec.MakeMeasureSpec(Control.MeasuredWidth, Android.Views.MeasureSpecMode.Exactly),
                    MeasureSpec.MakeMeasureSpec(Control.MeasuredHeight, Android.Views.MeasureSpecMode.Exactly));

            Layout(0, 0, MeasuredWidth, MeasuredHeight);
            Element.HeightRequest = MeasuredHeight / Context.Resources.DisplayMetrics.Density;
            Element.WidthRequest  = MeasuredWidth / Context.Resources.DisplayMetrics.Density;
        }
コード例 #2
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            if (Element == null)
            {
                return;
            }

            int width  = r - l;
            int height = b - t;

            _bottomBar.Measure(
                MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly),
                MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.AtMost));

            // We need to call measure one more time with measured sizes
            // in order to layout the bottom bar properly
            _bottomBar.Measure(
                MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly),
                MeasureSpec.MakeMeasureSpec(_bottomBar.ItemContainer.MeasuredHeight, MeasureSpecMode.Exactly));

            int barHeight = _bottomBar.ItemContainer.MeasuredHeight;

            // int barHeight = 150;

            _bottomBar.Layout(0, b - barHeight, width, b);

            float density = Android.Content.Res.Resources.System.DisplayMetrics.Density;



            double contentWidthConstraint  = width / density;
            double contentHeightConstraint = (height - barHeight) / density;

            if (_currentPage != null)
            {
                try
                {
                    var renderer = Platform.GetRenderer(_currentPage);

                    renderer.Element.Measure(contentWidthConstraint, contentHeightConstraint);
                    renderer.Element.Layout(new Rectangle(0, 0, contentWidthConstraint, contentHeightConstraint));

                    renderer.UpdateLayout();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }
        }
コード例 #3
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            if (Element == null)
            {
                return;
            }

            var statusBarHeight = 0;

            int resourceId = Resources.GetIdentifier("status_bar_height", "dimen", "android");

            if (resourceId > 0)
            {
                statusBarHeight = Resources.GetDimensionPixelSize(resourceId);
            }

            b -= statusBarHeight;

            int width  = r - l;
            int height = b - t;

            _bottomBar.Measure(
                MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly),
                MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.AtMost));

            // We need to call measure one more time with measured sizes
            // in order to layout the bottom bar properly
            _bottomBar.Measure(
                MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly),
                MeasureSpec.MakeMeasureSpec(_bottomBar.ItemContainer.MeasuredHeight, MeasureSpecMode.Exactly));

            int barHeight = _bottomBar.ItemContainer.MeasuredHeight;

            _bottomBar.Layout(0, b - barHeight, width, b);

            float density = Android.Content.Res.Resources.System.DisplayMetrics.Density;

            double contentWidthConstraint  = width / density;
            double contentHeightConstraint = (height - barHeight + statusBarHeight) / density;

            if (_currentPage != null)
            {
                var renderer = Platform.GetRenderer(_currentPage);

                renderer.Element.Measure(contentWidthConstraint, contentHeightConstraint);
                renderer.Element.Layout(new Rectangle(0, 0, contentWidthConstraint, contentHeightConstraint));

                renderer.UpdateLayout();
            }
        }
コード例 #4
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            mMaxChildWidth  = 0;
            mMaxChildHeight = 0;

            // Measure once to find the maximum child size.
            int childWidthMeasureSpec = MeasureSpec.MakeMeasureSpec(
                MeasureSpec.GetSize(widthMeasureSpec), MeasureSpecMode.AtMost);
            int childHeightMeasureSpec = MeasureSpec.MakeMeasureSpec(
                MeasureSpec.GetSize(widthMeasureSpec), MeasureSpecMode.AtMost);

            int count = ChildCount;

            for (int i = 0; i < count; i++)
            {
                var child = GetChildAt(i);

                if (child.Visibility == ViewStates.Gone)
                {
                    continue;
                }

                child.Measure(childWidthMeasureSpec, childHeightMeasureSpec);

                mMaxChildWidth  = Math.Max(mMaxChildWidth, child.MeasuredWidth);
                mMaxChildHeight = Math.Max(mMaxChildHeight, child.MeasuredHeight);
            }

            // Measure again for each child to be exactly the same size.
            childWidthMeasureSpec = MeasureSpec.MakeMeasureSpec(
                mMaxChildWidth, MeasureSpecMode.Exactly);
            childHeightMeasureSpec = MeasureSpec.MakeMeasureSpec(
                mMaxChildHeight, MeasureSpecMode.Exactly);

            for (int i = 0; i < count; i++)
            {
                var child = GetChildAt(i);

                if (child.Visibility == ViewStates.Gone)
                {
                    continue;
                }

                child.Measure(childWidthMeasureSpec, childHeightMeasureSpec);
            }

            SetMeasuredDimension(
                ResolveSize(mMaxChildWidth, widthMeasureSpec),
                ResolveSize(mMaxChildHeight, heightMeasureSpec));
        }
コード例 #5
0
        public void UpdateMarkerLayout()
        {
            var view           = Element;
            var _context       = Context;
            var headlessOffset = CompressedLayout.GetHeadlessOffset(view);
            var x      = (int)_context.ToPixels(view.X + headlessOffset.X);
            var y      = (int)_context.ToPixels(view.Y + headlessOffset.Y);
            var size   = view.Measure(double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.IncludeMargins);
            var width  = Math.Max(0, (int)_context.ToPixels(size.Request.Width));
            var height = Math.Max(0, (int)_context.ToPixels(size.Request.Height));

            Measure(MeasureSpec.MakeMeasureSpec(width, Android.Views.MeasureSpecMode.Unspecified), MeasureSpec.MakeMeasureSpec(height, Android.Views.MeasureSpecMode.Unspecified));
            Layout(x, y, x + width, y + height);
        }
コード例 #6
0
 protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
 {
     if (IsExpanded)
     {
         int expandSpec = MeasureSpec.MakeMeasureSpec(MeasuredSizeMask, MeasureSpecMode.AtMost);
         base.OnMeasure(widthMeasureSpec, expandSpec);
         ViewGroup.LayoutParams @params = LayoutParameters;
         @params.Height = this.MeasuredHeight;
     }
     else
     {
         base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
     }
 }
コード例 #7
0
ファイル: MvxGridView.cs プロジェクト: yzx4036/MvvmCross
 protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
 {
     if (NestedScrollingEnabled)
     {
         base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
     }
     else
     {
         //expand the view to the full height of it's contents to disable scrolling
         var expandSpec = MeasureSpec.MakeMeasureSpec(MeasuredSizeMask, MeasureSpecMode.AtMost);
         base.OnMeasure(widthMeasureSpec, expandSpec);
         LayoutParameters.Height = MeasuredHeight;
     }
 }
コード例 #8
0
ファイル: SmartListView.cs プロジェクト: lsgsk/SmartListView
 private void MeasureView(View v)
 {
     if (v.LayoutParameters != null)
     {
         int childWidthSpec  = MeasureSpec.MakeMeasureSpec(v.LayoutParameters.Width, MeasureSpecMode.Exactly);  //(v.Width, MeasureSpecMode.Exactly);
         int childHeightSpec = MeasureSpec.MakeMeasureSpec(v.LayoutParameters.Height, MeasureSpecMode.Exactly); //(v.Height, MeasureSpecMode.Unspecified);
         v.Measure(childWidthSpec, childHeightSpec);
     }
     else
     {
         v.Measure(0, 0);
     }
     v.Measure(MeasureSpec.MakeMeasureSpec((int)(v.MeasuredWidth * mScale), MeasureSpecMode.Exactly), MeasureSpec.MakeMeasureSpec((int)(v.MeasuredHeight * mScale), MeasureSpecMode.Exactly));
 }
コード例 #9
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (Expanded)
            {
                int expandSpec = MeasureSpec.MakeMeasureSpec(10000, MeasureSpecMode.AtMost);
                base.OnMeasure(widthMeasureSpec, expandSpec);

                LayoutParameters.Height = MeasuredHeight;
            }
            else
            {
                base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }
コード例 #10
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int contentViewHeight = 0;
            int childCount        = ChildCount;
            int menuWidthSpec     = MeasureSpec.MakeMeasureSpec(MeasureSpec.GetSize(widthMeasureSpec), MeasureSpec.GetMode(widthMeasureSpec));
            int menuHeightSpec    = MeasureSpec.MakeMeasureSpec(MeasureSpec.GetSize(heightMeasureSpec), MeasureSpec.GetMode(heightMeasureSpec));

            for (int i = 0; i < childCount; i++)
            {
                View view = GetChildAt(i);
                view.Measure(menuWidthSpec, menuHeightSpec);
                contentViewHeight += view.MeasuredHeight;
            }
            SetMeasuredDimension(MeasureSpec.GetSize(widthMeasureSpec), contentViewHeight);
        }
コード例 #11
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            var w = r - l;
            var h = b - t;

            var msw = MeasureSpec.MakeMeasureSpec(w, MeasureSpecMode.Exactly);
            var msh = MeasureSpec.MakeMeasureSpec(h, MeasureSpecMode.Exactly);

            view.Measure(msw, msh);
            view.Layout(0, 0, w, h);

            Log.Debug("OnLayout", $"{w} x {h}");
        }
コード例 #12
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            if (AndroidCoordinatorLayout == null)
            {
                return;
            }
            var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
            var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);

            //
            AndroidCoordinatorLayout?.Measure(msw, msh);
            AndroidCoordinatorLayout?.Layout(0, 0, r - l, b - t);
        }
コード例 #13
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            if (inited)
            {
                return;
            }

            inited = true;
            //base.OnLayout(changed, l, t, r, b);
            var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
            var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);

            view.Measure(msw, msh);
            view.Layout(0, 0, r - l, b - t);
        }
コード例 #14
0
ファイル: ButtonView.cs プロジェクト: Zebra/iFactr-Android
        /// <summary>
        /// Sets the location and size of the control within its parent grid.
        /// This is called by the underlying grid layout system and should not be used in application logic.
        /// </summary>
        /// <param name="location">The X and Y coordinates of the upper left corner of the control.</param>
        /// <param name="size">The width and height of the control.</param>
        public void SetLocation(Point location, Size size)
        {
            var left   = location.X;
            var right  = location.X + size.Width;
            var top    = location.Y;
            var bottom = location.Y + size.Height;

            Layout((int)left, (int)top, (int)right, (int)bottom);

            var widthSpec  = MeasureSpec.MakeMeasureSpec((int)size.Width, MeasureSpecMode.Exactly);
            var heightSpec = MeasureSpec.MakeMeasureSpec((int)size.Height, MeasureSpecMode.Exactly);

            _button.Measure(widthSpec, heightSpec);
            _button.Layout(-Padding, -Padding, (int)size.Width + Padding, (int)size.Height + Padding);
        }
コード例 #15
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            if (NotchLayout != null)
            {
                var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
                var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);

                NotchLayout.Measure(msw, msh);
                NotchLayout.Layout(0, 0, r - l, b - t);

                NotchLayout.Parent.BringChildToFront(NotchLayout);
            }
        }
コード例 #16
0
        public void MeasureItems(int columnWidth)
        {
            LayoutInflater inflater = mActivity.LayoutInflater;
            ItemView       itemView = (ItemView)inflater.Inflate(Resource.Layout.Item, null);

            int widthMeasureSpec  = MeasureSpec.MakeMeasureSpec(columnWidth, MeasureSpecMode.Exactly);
            int heightMeasureSpec = MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);

            for (int i = 0; i < mImageList.Count; ++i)
            {
                itemView.Position = i;

                itemView.RequestLayout();
                itemView.Measure(widthMeasureSpec, heightMeasureSpec);
            }
        }
コード例 #17
0
        protected float MeasureHeight(View.View tv)
        {
            if (tv.Visibility == ViewStates.Gone)
            {
                return(0);
            }

            var width = (int)fluentEngine.MeasuredWidth(tv) - PaddingLeft - PaddingRight;

            var widthSpec  = MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly);
            var heightSpec = MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);

            tv.Measure(widthSpec, heightSpec);

            return(tv.MeasuredHeight);
        }
コード例 #18
0
        /// <inheritdoc />
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            MeasureChild(_northArrow, MeasureSpec.MakeMeasureSpec(MeasureSpec.GetSize(widthMeasureSpec), MeasureSpecMode.AtMost), MeasureSpec.MakeMeasureSpec(MeasureSpec.GetSize(heightMeasureSpec), MeasureSpecMode.AtMost));

            // Calculate the ideal width and height for the view
            var desiredWidth  = PaddingLeft + PaddingRight + _northArrow.MeasuredWidth;
            var desiredHeight = PaddingTop + PaddingBottom + _northArrow.MeasuredHeight;

            // Get the width and height of the view given any width and height constraints indicated by the width and height spec values
            var width  = ResolveSize(desiredWidth, widthMeasureSpec);
            var height = ResolveSize(desiredHeight, heightMeasureSpec);

            SetMeasuredDimension(width, height);
        }
コード例 #19
0
 protected override void OnLayout(bool changed, int l, int t, int r, int b)
 {
     base.OnLayout(changed, l, t, r, b);
     if ((changed || _contentNeedsLayout) && this.Control != null)
     {
         if (_currentPage != null)
         {
             _currentPage.Layout(new Rectangle(0, 0, Element.Width, Element.Height));
         }
         var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
         var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);
         this.Control.Measure(msw, msh);
         this.Control.Layout(0, 0, r, b);
         _contentNeedsLayout = false;
     }
 }
コード例 #20
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            // Calculate entire height by providing a very large height hint.
            // View.MEASURED_SIZE_MASK represents the largest height possible.
            int expandSpec = MeasureSpec.MakeMeasureSpec(MeasuredSizeMask,
                                                         MeasureSpecMode.AtMost);

            base.OnMeasure(widthMeasureSpec, expandSpec);

            if (Width == 0 || Adapter == null)
            {
                return;
            }
            ViewGroup.LayoutParams param = LayoutParameters;
            param.Height = DimensionsHelper.DpToPx(Adapter.Count / (Width / ItemWidth) * ItemHeight);
        }
コード例 #21
0
        public void MeasureAndLayoutNative()
        {
            if (_childView != null)
            {
                IVisualElementRenderer renderer = Platform.GetRenderer(_childView);
                if (renderer.ViewGroup != null)
                {
                    var nativeView = renderer.ViewGroup;

                    var w = MeasureSpec.MakeMeasureSpec(nativeView.MeasuredWidth, MeasureSpecMode.Exactly);
                    var h = MeasureSpec.MakeMeasureSpec(nativeView.MeasuredHeight, MeasureSpecMode.Exactly);
                    nativeView.Measure(w, h);
                    nativeView.Layout(nativeView.Left, nativeView.Top, nativeView.Right, nativeView.Bottom);
                }
            }
        }
コード例 #22
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int radius = mRadius = ComputeRadius(Math.Abs(mToDegrees - mFromDegrees), ChildCount, mChildSize,
                                                 mChildPadding, MIN_RADIUS);
            int size = radius * 2 + mChildSize + mChildPadding + mLayoutPadding * 2;

            SetMeasuredDimension(size, size);

            int count = ChildCount;

            for (int i = 0; i < count; i++)
            {
                GetChildAt(i).Measure(MeasureSpec.MakeMeasureSpec(mChildSize, MeasureSpecMode.Exactly),
                                      MeasureSpec.MakeMeasureSpec(mChildSize, MeasureSpecMode.Exactly));
            }
        }
コード例 #23
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);
            if (!changed)
            {
                return;
            }
            var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
            var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);

            mainLayout.Measure(msw, msh);
            mainLayout.Layout(0, 0, r - l, b - t);

            capturePhotoButton.SetX(mainLayout.Width / 2 - 60);
            capturePhotoButton.SetY(mainLayout.Height - 200);
        }
コード例 #24
0
        void InitView()
        {
            NotchLayout = new LinearLayout(Container.Context);
            NotchLayout.LayoutParameters = new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, Android.Views.ViewGroup.LayoutParams.MatchParent);


            var button = new Android.Widget.Button(Container.Context);

            button.Text = "Notch";

            var page = Element as Page;

            if (NotchInfo.Model == PhoneModels.Custom)
            {
                Device = NotchInfo.CustomDevice;
            }
            else
            {
                Device = Devices[NotchInfo.Model];
            }


            var notch = new NotchView(Container.Context)
            {
                Device = Device
            };

            NotchLayout.AddView(notch);
            Container.AddView(NotchLayout);

            NotchLayout.Parent.BringChildToFront(NotchLayout);


            Container.LayoutChange += (sender, e) =>
            {
                if (NotchLayout != null)
                {
                    var msw = MeasureSpec.MakeMeasureSpec(e.Right, MeasureSpecMode.Exactly);
                    var msh = MeasureSpec.MakeMeasureSpec(e.Bottom, MeasureSpecMode.Exactly);

                    NotchLayout.Measure(msw, msh);
                    NotchLayout.Layout(0, 0, e.Right, e.Bottom);

                    NotchLayout.Parent.BringChildToFront(NotchLayout);
                }
            };
        }
コード例 #25
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            try
            {
                var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
                var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);

                _View.Measure(msw, msh);
                _View.Layout(0, 0, r - l, b - t);
            }
            catch (Exception ex)
            {
                Console.WriteLine("DROID_SCAN | OnLayout error", ex);
            }
        }
コード例 #26
0
        /// <summary>
        /// This is called during layout when the size of this view has changed.
        /// </summary>
        /// <param name="w">Current width of this view.</param>
        /// <param name="h">Current height of this view.</param>
        /// <param name="oldw">Old width of this view.</param>
        /// <param name="oldh">Old height of this view.</param>
        protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
        {
            base.OnSizeChanged(w, h, oldw, oldh);

            //
            // Adjust the size of all the menu buttons.
            //
            for (int i = 0; i < ChildCount; i++)
            {
                if (GetChildAt(i) is MenuButton button)
                {
                    button.LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.WrapContent, h / 2);
                }
            }

            Measure(MeasureSpec.MakeMeasureSpec(MeasuredWidth, MeasureSpecMode.Exactly), MeasureSpec.MakeMeasureSpec(MeasuredHeight, MeasureSpecMode.Exactly));
        }
コード例 #27
0
        public override Xamarin.Forms.Size Measure(string text, double fontSize, string fontName)
        {
            TextView textView = new TextView(global::Android.App.Application.Context);

            textView.Typeface = this.getTypeface(fontName);
            textView.SetText(text, TextView.BufferType.Normal);

            int    widthMeasureSpec  = MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);
            int    heightMeasureSpec = MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);
            double scale             = global::Android.App.Application.Context.Resources.DisplayMetrics.Density;

            textView.SetTextSize(ComplexUnitType.Sp, (float)fontSize);
            textView.Measure(widthMeasureSpec, heightMeasureSpec);
            // Add 1 to account for rounding error.
            // MeasuredWidth and MeasuredHeight are in pixels but the caller will want the result in Dips.
            return(new Xamarin.Forms.Size((textView.MeasuredWidth + 1) / scale, (textView.MeasuredHeight + 1) / scale));
        }
コード例 #28
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (IsExpanded())
            {
                // Calculate entire height by providing a very large height hint.
                // But do not use the highest 2 bits of this integer; those are
                // reserved for the MeasureSpec mode.
                int expandSpec = MeasureSpec.MakeMeasureSpec(int.MaxValue >> 2, Android.Views.MeasureSpecMode.AtMost);
                base.OnMeasure(widthMeasureSpec, expandSpec);

                this.LayoutParameters.Height = MeasuredHeight;
            }
            else
            {
                base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }
コード例 #29
0
ファイル: Marker.cs プロジェクト: llenroc/DiscreteSeekBar
        public void ResetSizes(String maxValue)
        {
            DisplayMetrics displayMetrics = Resources.DisplayMetrics;

            //Account for negative numbers... is there any proper way of getting the biggest string between our range????
            mNumber.Text = $"-{maxValue}";
            //Do a first forced measure call for the TextView (with the biggest text content),
            //to calculate the max width and use always the same.
            //this avoids the TextView from shrinking and growing when the text content changes
            int wSpec = MeasureSpec.MakeMeasureSpec(displayMetrics.WidthPixels, MeasureSpecMode.AtMost);
            int hSpec = MeasureSpec.MakeMeasureSpec(displayMetrics.HeightPixels, MeasureSpecMode.AtMost);

            mNumber.Measure(wSpec, hSpec);
            mWidth = Math.Max(mNumber.MeasuredWidth, mNumber.MeasuredHeight);
            RemoveView(mNumber);
            AddView(mNumber, new FrameLayout.LayoutParams(mWidth, mWidth, GravityFlags.Left | GravityFlags.Top));
        }
コード例 #30
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            if (Element == null)
            {
                return;
            }

            int width  = r - l;
            int height = b - t;

            _bottomBar.Measure(
                MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly),
                MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.AtMost));

            // In order to properly layout the tabbed at the bottom, we need to re-measure the size
            _bottomBar.Measure(
                MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly),
                MeasureSpec.MakeMeasureSpec(_bottomBar.ItemContainer.MeasuredHeight, MeasureSpecMode.Exactly));

            int barHeight = _bottomBar.ItemContainer.MeasuredHeight;


            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                _bottomBar.Layout(0, b - barHeight - 72, width, b);
            }
            else
            {
                _bottomBar.Layout(0, b - barHeight, width, b);
            }

            float density = Android.Content.Res.Resources.System.DisplayMetrics.Density;

            double contentWidthConstraint  = width / density;
            double contentHeightConstraint = (height - barHeight) / density;

            if (_currentPage != null)
            {
                var renderer = Platform.GetRenderer(_currentPage);

                renderer.Element.Measure(contentWidthConstraint, contentHeightConstraint);
                renderer.Element.Layout(new Rectangle(0, 0, contentWidthConstraint, contentHeightConstraint));

                renderer.UpdateLayout();
            }
        }