如何在 Xamarin.Forms 页面中获取标签栏高度 [英] How to get the tab bar height in a Xamarin.Forms page

查看:34
本文介绍了如何在 Xamarin.Forms 页面中获取标签栏高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的内容页面中显示图像,使其高度是页面高度的固定百分比.我使用具有星形单元行高的网格来执行此操作.但是,当内容页面放置在 TabbedPage 中时,总网格高度似乎是 [屏幕减去标签栏高度] 的高度,因此图像看起来会短一些.

I'm displaying an image within my content pages such that its height is a fixed percentage of the page height. I do this using a grid with star unit row height. However, when the content pages are placed within a TabbedPage, the total grid height seems to be that of [the screen minus the tab bar height], so as a consequence, the image appears a bit shorter.

如果我可以在我的内容页面中访问标签栏高度,这将是对百分比的简单调整.

If I could access the tab bar height within my content pages, it would be a simple adjustment to the percentage.

问题:

1) 如何获取内容页面中的标签栏高度?

1) How do I get the tab bar height within a content page?

2) 有没有更好的方法来达到预期的结果?

2) Is there a better way to achieve the desired result?

推荐答案

1) 如何获取内容页面中的标签栏高度?

1) How do I get the tab bar height within a content page?

我们无法直接从 PCL 获取标签栏高度.只需要为 TabbedRenderer

We can't get tabbar height from PCL directly.Just need a custom renderers for TabbedRenderer

[assembly: ExportRenderer(typeof(TabbedPage), 
typeof(CustomTabbedPageRenderer))]
namespace TabbedPageWithNavigationPage.iOS
{
    class CustomTabbedPageRenderer : TabbedRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            App.TabHeight = (int)TabBar.Frame.Height;
        }
    }
}

在PCL的App中定义TabHeight

public static int TabHeight { get; set; }

TabbedPage

protected override void OnAppearing()
{
    base.OnAppearing();
    int height = App.TabHeight;
}

2) 有没有更好的方法来达到预期的结果?

2) Is there a better way to achieve the desired result?

Image 上最好不要设置固定框,不要手动操作框.

We'r better not set the fixed frame on Image, and should not operate the frame manually .

Aspect可以帮助我们按照自己的意愿显示图像.

Aspect of Image can help us to show the image as we want.

这篇关于如何在 Xamarin.Forms 页面中获取标签栏高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆