Ejemplo n.º 1
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            TabLayout      tabs    = _tabLayout;
            FormsViewPager pager   = _viewPager;
            Context        context = Context;
            int            width   = r - l;
            int            height  = b - t;

            tabs.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost));
            var tabsHeight = 0;

            if (tabs.Visibility != ViewStates.Gone)
            {
                //MinimumHeight is only available on API 16+
                if ((int)Build.VERSION.SdkInt >= 16)
                {
                    tabsHeight = Math.Min(height, Math.Max(tabs.MeasuredHeight, tabs.MinimumHeight));
                }
                else
                {
                    tabsHeight = Math.Min(height, tabs.MeasuredHeight);
                }
            }

            pager.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.AtMost), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost));

            if (width > 0 && height > 0)
            {
                PageController.ContainerArea = new Rectangle(0, context.FromPixels(tabsHeight), context.FromPixels(width), context.FromPixels(height - tabsHeight));

                for (var i = 0; i < PageController.InternalChildren.Count; i++)
                {
                    var child = PageController.InternalChildren[i] as VisualElement;
                    if (child == null)
                    {
                        continue;
                    }
                    IVisualElementRenderer renderer = Android.Platform.GetRenderer(child);
                    var navigationRenderer          = renderer as NavigationPageRenderer;
                    if (navigationRenderer != null)
                    {
                        navigationRenderer.ContainerPadding = tabsHeight;
                    }
                }

                pager.Layout(0, 0, width, b);
                // We need to measure again to ensure that the tabs show up
                tabs.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(tabsHeight, MeasureSpecMode.Exactly));
                tabs.Layout(0, 0, width, tabsHeight);

                UpdateTabBarTranslation(pager.CurrentItem, 0);
            }

            base.OnLayout(changed, l, t, r, b);
        }
Ejemplo n.º 2
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            FormsViewPager pager   = _viewPager;
            Context        context = Context;
            int            width   = r - l;
            int            height  = b - t;

            pager.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.AtMost), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost));

            if (width > 0 && height > 0)
            {
                PageController.ContainerArea = new Rectangle(0, 0, context.FromPixels(width), context.FromPixels(height));
                pager.Layout(0, 0, width, b);
            }

            base.OnLayout(changed, l, t, r, b);
        }
Ejemplo n.º 3
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            FormsViewPager pager   = _viewPager;
            Context        context = Context;

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

            if (IsBottomTabPlacement)
            {
                if (width <= 0 || height <= 0)
                {
                    return;
                }

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

                pager.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.AtMost), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost));

                if (width > 0 && height > 0)
                {
                    PageController.ContainerArea = new Rectangle(0, 0, context.FromPixels(width), context.FromPixels(height - _bottomNavigationView.MeasuredHeight));

                    SetNavigationRendererPadding(0, _bottomNavigationView.MeasuredHeight);

                    pager.Layout(0, 0, width, b);
                    // We need to measure again to ensure that the tabs show up
                    _relativeLayout.Measure(
                        MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly),
                        MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly));
                    _relativeLayout.Layout(0, 0, _relativeLayout.MeasuredWidth, _relativeLayout.MeasuredHeight);
                }
            }
            else
            {
                TabLayout tabs = _tabLayout;

                tabs.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost));
                var tabsHeight = 0;

                if (tabs.Visibility != ViewStates.Gone)
                {
                    //MinimumHeight is only available on API 16+
                    if ((int)Build.VERSION.SdkInt >= 16)
                    {
                        tabsHeight = Math.Min(height, Math.Max(tabs.MeasuredHeight, tabs.MinimumHeight));
                    }
                    else
                    {
                        tabsHeight = Math.Min(height, tabs.MeasuredHeight);
                    }
                }

                pager.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.AtMost), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost));

                if (width > 0 && height > 0)
                {
                    PageController.ContainerArea = new Rectangle(0, context.FromPixels(tabsHeight), context.FromPixels(width), context.FromPixels(height - tabsHeight));

                    SetNavigationRendererPadding(tabsHeight, 0);

                    pager.Layout(0, 0, width, b);
                    // We need to measure again to ensure that the tabs show up
                    tabs.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(tabsHeight, MeasureSpecMode.Exactly));
                    tabs.Layout(0, 0, width, tabsHeight);

                    UpdateTabBarTranslation(pager.CurrentItem, 0);
                }
            }

            base.OnLayout(changed, l, t, r, b);
        }