Xamarin形式标签定位
问题描述:
新手在这里。我们使用XAML的XAML &在页面的顶部添加了一个标签,但标签太靠近页面的顶部,所以它被iPad当前时间遮挡。Xamarin形式标签定位
使用XAML代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamlSamples.HelloXamlPage"
Title="XAML + Code Page">
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#000000" Spacing="0" Padding="-300,-1,-300,29">
<Label Text="Text here"
Font="Large"
TextColor="White"
HorizontalOptions="Center"
VerticalOptions="Center"
Style="{DynamicResource TitleStyle}"/>
</StackLayout>
</ContentPage>
答
看看你堆栈填充(填充= “ - 300,-1,-300,29”),这是一个有点怪异, 此外,您还可以用填充添加一些布局之前
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#000000" Spacing="0" Padding="-300,-1,-300,29">
<Grid Padding="20 "/>
<Label Text="Text here"
Font="Large"
TextColor="White"
HorizontalOptions="Center"
VerticalOptions="Center"
Style="{DynamicResource TitleStyle}"/>
答
您的填充更改为
Padding="x, 20, y, z"
在iOS中,状态栏的高度为20像素,并且在确定页面上的位置时(即y的位置位于状态栏的顶部并且类似于页面)时包含在内。在确定页面上的位置时(意味着0的位置位于状态栏的底部),Windows和Android不包括状态栏的高度。还应该注意的是,在某些情况下,状态栏可能实际上是40像素高(在我读过的电话中)。
一个跨平台的选择建议的用途是做这样的事情:
<ContentPage.Padding>
<!-- set platform - specific padding
iOS needs an additional
20px top padding to account for
iPhone status bar -->
< OnPlatform x:TypeArguments ="Thickness"
iOS ="0, 20, 0, 0"
Android ="0, 0, 0, 0"
WinPhone ="0, 0, 0, 0" />
</ ContentPage.Padding >
注:此填充被添加到您的ContentPage
标签,而不是StackLayout
标签。代码从here检索。
填充=“20”工作正常,谢谢。 – Joseph2302