コード例 #1
0
        void SetTitlePosition(CustomNavigationPage.TitleAlignment alignment, Thickness padding, Thickness margin, CGRect vFrame)
        {
            var marginX       = margin.Top;
            var marginY       = margin.Left;
            var marginWidth   = margin.Left + margin.Right;
            var marginHeight  = margin.Top + margin.Bottom;
            var paddingWidth  = padding.Left + padding.Right;
            var paddingHeight = padding.Top + padding.Bottom;
            var paddingX      = padding.Left;
            var paddingY      = padding.Top;

            if (CustomNavigationPage.GetTitleBackground(Element) != null && vFrame.Width == 0 && vFrame.Height == 0)
            {
                vFrame = titleView.Frame;
            }


            marginView.Frame = new CGRect(vFrame.X, vFrame.Y, vFrame.Width, vFrame.Height);



            double offset = 0;

            titleLabel.AutoresizingMask = UIViewAutoresizing.All;
            switch (alignment)
            {
            case CustomNavigationPage.TitleAlignment.Start:
                marginView.Frame = new CGRect(vFrame.X, marginView.Frame.Y, marginView.Bounds.Width + marginWidth + paddingWidth, marginView.Bounds.Height + marginHeight + paddingHeight);
                var startCenter = marginView.Center;
                startCenter.Y               = marginView.Superview.Center.Y;
                marginView.Center           = startCenter;
                titleLabel.TextAlignment    = UITextAlignment.Left;
                subtitleLabel.TextAlignment = UITextAlignment.Left;
                offset = marginX;
                break;

            case CustomNavigationPage.TitleAlignment.Center:
                offset                      = marginX;
                marginView.Frame            = new CGRect(marginView.Frame.X, marginView.Frame.Y, marginView.Bounds.Width + marginWidth + paddingWidth, marginView.Bounds.Height + marginHeight + paddingHeight);
                marginView.Center           = marginView.Superview.Center;
                titleLabel.TextAlignment    = UITextAlignment.Center;
                subtitleLabel.TextAlignment = UITextAlignment.Center;
                break;

            case CustomNavigationPage.TitleAlignment.End:

                var endCenter = marginView.Center;
                endCenter.Y       = marginView.Superview.Center.Y;
                marginView.Center = endCenter;

                titleLabel.TextAlignment    = UITextAlignment.Right;
                subtitleLabel.TextAlignment = UITextAlignment.Right;
                marginView.Frame            = new CGRect(marginView.Superview.Frame.Width - marginView.Frame.Width - offset - marginWidth - paddingWidth, marginView.Frame.Y, marginView.Bounds.Width + marginWidth + paddingWidth, marginView.Bounds.Height + marginHeight + paddingHeight);
                offset = marginView.Frame.Width - vFrame.Width - paddingWidth - marginX;
                break;
            }

            titleView.Frame = new CGRect(offset, vFrame.Y + marginY, vFrame.Width + paddingWidth, vFrame.Height + paddingHeight);

            var cPage = Element as CustomPage;



            if (cPage != null && (!string.IsNullOrEmpty(cPage.Subtitle) || (cPage.FormattedSubtitle != null && cPage.FormattedSubtitle.Spans.Count > 0)))
            {
                titleLabel.Frame = new CGRect(paddingX, paddingY, titleView.Frame.Width, titleLabel.IntrinsicContentSize.Height);


                subtitleLabel.Frame = new CGRect(titleLabel.Frame.X, titleLabel.Frame.Y + titleLabel.Frame.Height + 3, titleView.Frame.Width, subtitleLabel.Frame.Height);
            }
            else
            {
                titleLabel.Frame = new CGRect(paddingX, paddingY, titleLabel.IntrinsicContentSize.Width, titleLabel.IntrinsicContentSize.Height);
            }
        }
コード例 #2
0
        void UpdateTitleViewLayoutAlignment(LinearLayout titleViewLayout, AppCompatTextView titleTextView, AppCompatTextView subTitleTextView, CustomNavigationPage.TitleAlignment alignment)
        {
            var titleViewParams        = titleViewLayout.LayoutParameters as Android.Widget.FrameLayout.LayoutParams;
            var titleTextViewParams    = titleTextView.LayoutParameters as LinearLayout.LayoutParams;
            var subTitleTextViewParams = subTitleTextView.LayoutParameters as LinearLayout.LayoutParams;

            switch (alignment)
            {
            case CustomNavigationPage.TitleAlignment.Start:
                titleViewParams.Gravity        = GravityFlags.Start | GravityFlags.CenterVertical;
                titleTextViewParams.Gravity    = GravityFlags.Start;
                subTitleTextViewParams.Gravity = GravityFlags.Start;

                break;

            case CustomNavigationPage.TitleAlignment.Center:

                titleViewParams.Gravity        = GravityFlags.Center;
                titleTextViewParams.Gravity    = GravityFlags.Center;
                subTitleTextViewParams.Gravity = GravityFlags.Center;
                break;

            case CustomNavigationPage.TitleAlignment.End:
                titleViewParams.Gravity        = GravityFlags.End | GravityFlags.CenterVertical;
                titleTextViewParams.Gravity    = GravityFlags.End;
                subTitleTextViewParams.Gravity = GravityFlags.End;
                break;
            }


            titleViewLayout.LayoutParameters = titleViewParams;
        }
コード例 #3
0
        void UpdateTitleViewLayoutAlignment(LinearLayout titleViewLayout, Android.Widget.TextView titleTextView, Android.Widget.TextView subTitleTextView, CustomNavigationPage.TitleAlignment alignment)
        {
            var titleViewParams        = titleViewLayout.LayoutParameters as Android.Support.V7.App.ActionBar.LayoutParams;
            var titleTextViewParams    = titleTextView.LayoutParameters as LinearLayout.LayoutParams;
            var subTitleTextViewParams = subTitleTextView.LayoutParameters as LinearLayout.LayoutParams;
            var leftMenuParams         = _leftMenuLayout.LayoutParameters as Android.Support.V7.App.ActionBar.LayoutParams;
            var rightMenuParams        = _rightMenuLayout.LayoutParameters as Android.Support.V7.App.ActionBar.LayoutParams;

            switch (alignment)
            {
            case CustomNavigationPage.TitleAlignment.Start:
                titleViewParams.Gravity        = (int)GravityFlags.Start;
                titleTextViewParams.Gravity    = GravityFlags.Start;
                subTitleTextViewParams.Gravity = GravityFlags.Start;

                break;

            case CustomNavigationPage.TitleAlignment.Center:
                leftMenuParams.Gravity         = (int)GravityFlags.Start;
                rightMenuParams.Gravity        = (int)GravityFlags.End;
                rightMenuParams.MarginEnd      = 20;
                titleViewParams.Gravity        = (int)GravityFlags.Center;
                titleTextViewParams.Gravity    = GravityFlags.Center;
                subTitleTextViewParams.Gravity = GravityFlags.Center;
                break;

            case CustomNavigationPage.TitleAlignment.End:
                titleViewParams.Gravity        = (int)GravityFlags.End;
                titleTextViewParams.Gravity    = GravityFlags.End;
                subTitleTextViewParams.Gravity = GravityFlags.End;
                break;
            }


            titleViewLayout.LayoutParameters = titleViewParams;
        }