Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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
C# 相对布局中的布局项(XAML)_C#_Xamarin_Xamarin.forms - Fatal编程技术网

C# 相对布局中的布局项(XAML)

C# 相对布局中的布局项(XAML),c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我试图有一个水平居中的图像,然后在它下面放置一个文本框,也水平居中 从我看到的所有示例中,在硬编码之前需要知道相对视图的宽度和高度。情况肯定不是这样吗 以下是我到目前为止所做的尝试 <RelativeLayout> <Image x:Name="logo" Source="logo.png" HorizontalOptions="CenterAndExpand"/> <StackLayout Orientation=

我试图有一个水平居中的图像,然后在它下面放置一个文本框,也水平居中

从我看到的所有示例中,在硬编码之前需要知道相对视图的宽度和高度。情况肯定不是这样吗

以下是我到目前为止所做的尝试

        <RelativeLayout>
        <Image x:Name="logo" Source="logo.png" HorizontalOptions="CenterAndExpand"/>

        <StackLayout Orientation="Horizontal"
            BackgroundColor="Lime"
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, 
                                    Property=Width,
                                    Factor=0.5"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, 
                                    ElementName=logo
                                    Property=Y,
                                    Constant=100}">
            <Entry Text="{Binding Email, Mode=TwoWay}" Keyboard="Email" x:Name="signUpemailEntry" Placeholder="Email" TextColor="#2980b9" WidthRequest="270"  BackgroundColor="Fuchsia">
                <Entry.Behaviors>
                    <behave:EmailValidatorBehaviour x:Name="signUpemailValidator"/>
                 </Entry.Behaviors>
            </Entry>

            <Image x:Name="signUpemailSuccessErrorImage"
                  Style="{Binding Source={x:Reference emailValidator}, 
                          Path=IsValid, 
                          Converter={StaticResource boolToStyleImage}}"/>
       </StackLayout>
    </RelativeLayout>

不确定这是否是您所需要的,但为了实现您的目标,您需要将图像和文本放在RelativeLayout内的相同堆栈布局中

<?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="TestRelativeLayout.MyPage">
    <ContentPage.Content>
           <RelativeLayout>
        <StackLayout Orientation="Vertical">
            <Image x:Name="logo" Source="postage1.jpg" HorizontalOptions="Center"/>
            <Entry Text="Test" Keyboard="Email" x:Name="signUpemailEntry"
            Placeholder="Email" TextColor="#2980b9" WidthRequest="270"
            BackgroundColor="Fuchsia"
            HorizontalOptions="Center"/>
       </StackLayout>
    </RelativeLayout>
    </ContentPage.Content>
</ContentPage>


如果您希望一个元素位于另一个元素之下,为什么不使用垂直堆叠布局?我认为你的布局,加上所有这些限制,对于这么简单的目的来说太复杂了。。。编辑:如果你需要把条目放在logo下面,而不是第二张图片,我认为最好的布局是网格。只需将徽标和条目放在第一列,第二个图像将在第二列。@Grisha我想要相对布局的原因是将添加更多的项目。其中一个是一个按钮,它需要停靠在屏幕的底部,但我认为网格可以更好地为您服务。它的布局非常灵活。你可以把这个按钮放在单独的最后一行中(高度设置为自动),这样就可以了…相对布局在这里有什么用?