Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml Xamarin在图像上形成垂直居中的文本_Xaml_Xamarin_Xamarin.forms - Fatal编程技术网

Xaml Xamarin在图像上形成垂直居中的文本

Xaml Xamarin在图像上形成垂直居中的文本,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我正在学习Xamarin,我想在这张图片上显示一张图片作为背景,并加上一些文字 就这样,我设法完成了,但是文本显示在图像的左上角 我希望文本被放置在图像的垂直中心,但要坚持在它的左侧 到目前为止,我的代码是XAML: <Grid RowSpacing="0"> <Grid.RowDefinitions> <RowDefinition Height="20*" ></RowDefinition>

我正在学习Xamarin,我想在这张图片上显示一张图片作为背景,并加上一些文字

就这样,我设法完成了,但是文本显示在图像的左上角

我希望文本被放置在图像的垂直中心,但要坚持在它的左侧

到目前为止,我的代码是XAML:

<Grid RowSpacing="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="20*" ></RowDefinition>
            <RowDefinition Height="65*"></RowDefinition>
            <RowDefinition Height="15*"></RowDefinition>
        </Grid.RowDefinitions>

        <RelativeLayout Grid.Row="0">
            <Image Source="login.png" Aspect="Fill" />
            <Label Text="Bem vindo" TextColor="White" FontSize="22"></Label>
        </RelativeLayout>

        <Label Grid.Row="1" Text="linha 2" BackgroundColor="Coral"></Label>
        <Button Grid.Row="2" Text="linha 3" BackgroundColor="DarkRed"></Button>
    </Grid>

我尝试过垂直选择之类的,但没有效果

这样做的一件事是将Maring属性设置到标签上,但是那样的话,标签将只对我正在测试的设备居中。其他设备,无论大小,标签可能(也可能)放置在错误的位置


有什么帮助吗?

您不需要网格中的RelativeLayout。网格本身已经能够处理视图覆盖,并且让代码更清晰

它可以工作:

<Grid RowSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="20*"></RowDefinition>
        <RowDefinition Height="65*"></RowDefinition>
        <RowDefinition Height="15*"></RowDefinition>
    </Grid.RowDefinitions>

    <Image Grid.Row="0" Grid.Column="0"
           Source="login.png"
           HorizontalOptions="FillAndExpand"
           VerticalOptions="FillAndExpand" 
           Aspect="Fill" />
    <Label Grid.Row="0" Grid.Column="0"
           Text="Bem vindo" 
           HorizontalOptions="FillAndExpand"
           VerticalOptions="FillAndExpand"
           HorizontalTextAlignment="Start"
           VerticalTextAlignment="Center"
           TextColor="White" 
           FontSize="22"/>

    <Label Grid.Row="1" 
           Text="linha 2" 
           BackgroundColor="Coral"/>
    <Button Grid.Row="2" 
            Text="linha 3" 
            BackgroundColor="DarkRed"/>
</Grid>


根据JDalri的描述,HorizontalTextAlignment应该启动。你说得对@ColeXia,我没有注意到这一点。现在我编辑了答案。非常感谢。