网格不以xamarin形式填充父网格

时间:2017-09-27 01:35:34

标签: xaml xamarin mobile layout xamarin.forms

在我的xamarin表单项目中 我需要白色网格填充aqua Grid。没有relativeLayout它没有发生,所以,我试图使用相对布局,但它仍然没有工作.... 我现在没有想法......为什么会这样?

现在怎么样:

enter image description here

这是此页面网格的我的xaml代码:

<RelativeLayout VerticalOptions="FillAndExpand">
                        <!--Picker Grid-->
                        <Grid BackgroundColor="Aqua" x:Name="lojas_grid_picker" VerticalOptions="FillAndExpand"
                          RelativeLayout.WidthConstraint="{ConstraintExpression
                                            Type=RelativeToParent,
                                            Property=Width,
                                            Factor=1,
                                            Constant=0}">


                            <Image Source="pickers.png"
                                   Opacity="0.5"
                       Aspect="Fill"
                       VerticalOptions="FillAndExpand"
                       Grid.Row="0"
                       Grid.Column="0"
                                   RelativeLayout.WidthConstraint="{ConstraintExpression
                                            Type=RelativeToParent,
                                            Property=Width,
                                            Factor=1,
                                            Constant=0}"/>

                            <!--left, top, right, bottom-->
                            <!--<StackLayout
                   x:Name="lojas_stack_pickers"
                   Grid.Row="0"
                   Grid.Column="0" 
                   VerticalOptions="CenterAndExpand">

                    <StackLayout.Padding>
                        <OnPlatform x:TypeArguments="Thickness"
                             Android="10, 5, 30, 30"
                             iOS="10, 10, 30, 30"/>
                    </StackLayout.Padding>

                    <StackLayout.Spacing>
                        <OnPlatform x:TypeArguments="x:Double"
                             Android="10"
                             iOS="50"/>
                    </StackLayout.Spacing>-->
                            <Grid  BackgroundColor="White" Grid.Row="0" Grid.Column="0" x:Name="lojas_stack_pickers" VerticalOptions="FillAndExpand"

                                   RelativeLayout.XConstraint =
                                    "{ConstraintExpression Type=RelativeToParent,
                                    Property=X,
                                    Factor=1,
                                    Constant=0}"
                                    RelativeLayout.YConstraint =
                                   "{ConstraintExpression Type=RelativeToParent,
                                    Property=Y,
                                    Factor=1,
                                    Constant=0}" 

                                   RelativeLayout.WidthConstraint="{ConstraintExpression
                                            Type=RelativeToParent,
                                            Property=Width,
                                            Factor=1,
                                            Constant=0}"
                                    RelativeLayout.HeightConstraint="{ConstraintExpression
                                        Type=RelativeToView,
                                        ElementName=lojas_grid_picker,
                                        Property=Height,
                                        Factor=1,
                                        Constant=0}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="3*"/>
                                    <RowDefinition Height="3*"/>
                                    <RowDefinition Height="4*"/>
                                </Grid.RowDefinitions>

                                <Picker Grid.Row="0" x:Name="estadopicker" TextColor="{StaticResource MarromEscuro}" Title="Estado" SelectedIndexChanged="PickerEstado_SelectedindexChanged" VerticalOptions="FillAndExpand"/>

                                <Picker Grid.Row="1" x:Name="cidadepicker" TextColor="{StaticResource MarromEscuro}" VerticalOptions="FillAndExpand" ItemsSource="{Binding cidadeItems}" Title="Cidade" SelectedIndexChanged="PickerCidade_SelectedindexChanged"/>

                                <Picker Grid.Row="2" Margin="0,0,0,20" x:Name="lojapicker" VerticalOptions="FillAndExpand" TextColor="{StaticResource MarromEscuro}" Title="Loja" SelectedIndexChanged="PickerLoja_SelectedindexChanged"/>
                            </Grid>
                            <!--</StackLayout>-->

                    </Grid>
                    <!--Picker Grid-->

                    </RelativeLayout>

完整代码:

<?xaml 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="neoFly_Montana.Views.ProcuraLojasView"
         xmlns:local="clr-namespace:neoFly_Montana.LayoutScripts"
         Title="Nossas Lojas">

<ContentPage.Content>

    <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >

        <Image Source="backgroundlojas.jpg" Grid.Row="0" Grid.Column="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Aspect="Fill"/>

        <StackLayout Grid.Row="0" Grid.Column="0" HorizontalOptions="Fill" VerticalOptions="FillAndExpand">

            <StackLayout VerticalOptions="CenterAndExpand" Padding="60">

                <Label Text="Escolha uma loja" Style="{StaticResource labelsfont}" Margin="0,0,30,0" FontSize="Large" TextColor="White"/>

                <StackLayout Spacing="0">

                    <RelativeLayout 
                                            VerticalOptions="FillAndExpand">
                        <!--Picker Grid-->
                        <Grid BackgroundColor="Aqua" x:Name="lojas_grid_picker" VerticalOptions="FillAndExpand"
                          RelativeLayout.WidthConstraint="{ConstraintExpression
                                            Type=RelativeToParent,
                                            Property=Width,
                                            Factor=1,
                                            Constant=0}">


                            <Image Source="pickers.png"
                                   Opacity="0.5"
                       Aspect="Fill"
                       VerticalOptions="FillAndExpand"
                       Grid.Row="0"
                       Grid.Column="0"
                                   RelativeLayout.WidthConstraint="{ConstraintExpression
                                            Type=RelativeToParent,
                                            Property=Width,
                                            Factor=1,
                                            Constant=0}"/>

                            <!--left, top, right, bottom-->
                            <!--<StackLayout
                   x:Name="lojas_stack_pickers"
                   Grid.Row="0"
                   Grid.Column="0" 
                   VerticalOptions="CenterAndExpand">

                    <StackLayout.Padding>
                        <OnPlatform x:TypeArguments="Thickness"
                             Android="10, 5, 30, 30"
                             iOS="10, 10, 30, 30"/>
                    </StackLayout.Padding>

                    <StackLayout.Spacing>
                        <OnPlatform x:TypeArguments="x:Double"
                             Android="10"
                             iOS="50"/>
                    </StackLayout.Spacing>-->
                            <Grid  BackgroundColor="White" Grid.Row="0" Grid.Column="0" x:Name="lojas_stack_pickers" VerticalOptions="FillAndExpand"

                                   RelativeLayout.XConstraint =
                                    "{ConstraintExpression Type=RelativeToParent,
                                    Property=X,
                                    Factor=1,
                                    Constant=0}"
                                    RelativeLayout.YConstraint =
                                   "{ConstraintExpression Type=RelativeToParent,
                                    Property=Y,
                                    Factor=1,
                                    Constant=0}" 

                                   RelativeLayout.WidthConstraint="{ConstraintExpression
                                            Type=RelativeToParent,
                                            Property=Width,
                                            Factor=1,
                                            Constant=0}"
                                    RelativeLayout.HeightConstraint="{ConstraintExpression
                                        Type=RelativeToView,
                                        ElementName=lojas_grid_picker,
                                        Property=Height,
                                        Factor=1,
                                        Constant=0}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="3*"/>
                                    <RowDefinition Height="3*"/>
                                    <RowDefinition Height="4*"/>
                                </Grid.RowDefinitions>

                                <Picker Grid.Row="0" x:Name="estadopicker" TextColor="{StaticResource MarromEscuro}" Title="Estado" SelectedIndexChanged="PickerEstado_SelectedindexChanged" VerticalOptions="FillAndExpand"/>

                                <Picker Grid.Row="1" x:Name="cidadepicker" TextColor="{StaticResource MarromEscuro}" VerticalOptions="FillAndExpand" ItemsSource="{Binding cidadeItems}" Title="Cidade" SelectedIndexChanged="PickerCidade_SelectedindexChanged"/>

                                <Picker Grid.Row="2" Margin="0,0,0,20" x:Name="lojapicker" VerticalOptions="FillAndExpand" TextColor="{StaticResource MarromEscuro}" Title="Loja" SelectedIndexChanged="PickerLoja_SelectedindexChanged"/>
                            </Grid>
                            <!--</StackLayout>-->

                    </Grid>
                    <!--Picker Grid-->

                    </RelativeLayout>

                    <Label x:Name="lbl_ou" Text="ou" Style="{StaticResource labelsfont}" TextColor="White" FontSize="Large"/>

                    <!--Loja mais próxima Grid-->
                    <Grid x:Name="loja_prox_btn" VerticalOptions="EndAndExpand">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <Image Source="lojamaisproximabtn.png"
                   Aspect="Fill"
                   Grid.Row="0"
                   Grid.Column="0">
                            <Image.GestureRecognizers>
                                <TapGestureRecognizer Tapped="BtnOnTapGestureRecognizerTapped"/>
                            </Image.GestureRecognizers>
                        </Image>

                        <StackLayout 
                    Orientation="Horizontal"
                    VerticalOptions="Center"
                    HorizontalOptions="Center"
                    Margin="0,30,0,15"
                    Grid.Row="0"
                    Grid.Column="0">
                            <Image Source="reloadicon.png" VerticalOptions="Center"/>

                            <Label Text="Vá para a loja mais próxima" VerticalOptions="Center" FontAttributes="Bold" FontSize="Micro" FontFamily="Arial" TextColor="{StaticResource MarromEscuro}"/>
                        </StackLayout>

                    </Grid>
                    <!--Loja mais próxima Grid-->
                </StackLayout>
            </StackLayout>

            <!--Rodapé Grid-->
            <RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand">
                <Grid
                   RelativeLayout.WidthConstraint =
  "{ConstraintExpression Type=RelativeToParent,
                         Property=Width,
                         Factor=1,
                         Constant=0}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <Image Source="rodape.png"
                   Margin="0,20,0,0"
                   Aspect="Fill"
                   HorizontalOptions="FillAndExpand"
                   Grid.Row="0"
                   Grid.Column="0">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer Tapped="FranqueadoOnTapGestureRecognizerTapped"/>
                        </Image.GestureRecognizers>
                    </Image>

                    <!--Escrito Rodapé-->
                    <StackLayout Orientation="Vertical"
                   VerticalOptions="EndAndExpand"
                   HorizontalOptions="FillAndExpand"
                   Grid.Row="0"
                   Spacing="0"
                   Grid.Column="0">

                        <Image Source="franqButton.png">
                            <Image.Scale>
                                <OnPlatform x:TypeArguments="x:Double"
                                 iOS="0.75"
                                        Android="0.75"/>
                            </Image.Scale>
                        </Image>

                        <StackLayout Spacing="0" Orientation="Horizontal" HorizontalOptions="Center" 
                         Margin="0,0,0,10">

                            <local:MyLabel NamedFontSize="Medium" 
                   FontSizeFactor="0.7" 
                   Text="SEJA UM FRANQUEADO: "
                   TextColor="White"
                   FontAttributes="Bold"
                   Style="{StaticResource labelsfont}"/>

                            <local:MyLabel NamedFontSize="Medium" 
                   FontSizeFactor="0.7" Text="montanaexpress.com"
                   Style="{StaticResource labelsfont}"
                   TextColor="{StaticResource laranjacolor}"/>

                        </StackLayout>

                    </StackLayout>
                </Grid>
            </RelativeLayout>
        </StackLayout>

    </Grid>
</ContentPage.Content>

有什么问题?

0 个答案:

没有答案