gpt4 book ai didi

xamarin - 如何在 Xamarin.Forms 页面中获取标签栏高度

转载 作者:行者123 更新时间:2023-12-03 22:20:09 30 4
gpt4 key购买 nike

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

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

题:

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

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

最佳答案

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



我们无法直接从 PCL 获取标签栏高度。只需要为 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;
}
}
}

定义 TabHeightApp在 PCL
public static int TabHeight { get; set; }

获取 TabbedPage 中的高度
protected override void OnAppearing()
{
base.OnAppearing();
int height = App.TabHeight;
}

enter image description here

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



最好不要在Image上设置固定框,也不要手动操作框。
AspectImage可以帮助我们根据需要显示图像。

适合度

enter image description here

纵横比

enter image description here



enter image description here

关于xamarin - 如何在 Xamarin.Forms 页面中获取标签栏高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47689869/

30 4 0