Xamarin形成StackLayout,两个帧没有填满屏幕

时间:2016-08-05 21:16:24

标签: xamarin.forms

我看到一种我无法理解的非常奇怪的行为。我将两个Frame放在垂直方向的StackLayout中。第一帧'垂直选项设置为StartAndExpand,它正确呈现,但第二帧' VerticalOption设置为FillAndExpand,由于某些奇怪的原因,它不会在第一帧之后但是从屏幕中间跟随。我希望第二帧在第一帧之后立即跟随并占据整个屏幕。 代码如下:

 <RelativeLayout 
        x:Name="mainLayout"         
        HorizontalOptions="FillAndExpand"
        VerticalOptions="FillAndExpand"
        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
        RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}">      
            <StackLayout 
                    Padding="5,5,5,5"
                    BackgroundColor="Transparent"
                    HorizontalOptions="FillAndExpand"
                    Orientation="Vertical"
                    Spacing="0"
                    VerticalOptions="FillAndExpand"
                    RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
                    RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.88}" >
                <Frame 
                    OutlineColor="Silver"
                    BackgroundColor="#FFFFFF"
                    VerticalOptions="StartAndExpand"
                    HasShadow="False" >
                    <StackLayout 
                            BackgroundColor="Transparent">
                        <RelativeLayout
                            RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
                            HorizontalOptions="FillAndExpand">
                            <Label 
                                x:Name="To_Label"
                                RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.2}"
                                RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0}"
                                FontSize="Micro"
                                TranslationY="7"
                                FontAttributes="Bold"
                                HorizontalOptions="FillAndExpand"
                                VerticalOptions="CenterAndExpand"
                                TextColor="#2A84D3"
                                Text="To:">

                            </Label>
                            <Controls:DoneEntry x:Name="To_Entry"
                                    Text="{Binding Model.To}"
                                    RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.22}"
                                    RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.70}"
                                    VerticalOptions="CenterAndExpand"
                                    HorizontalOptions="FillAndExpand" >
                                <CorcavBehaviors:Interaction.Behaviors>
                                    <CorcavBehaviors:BehaviorCollection>
                                        <PounceBehaviors:EntryTextChanged Command="{Binding ReceipientTextChangeCommand}"/>
                                    </CorcavBehaviors:BehaviorCollection>
                                </CorcavBehaviors:Interaction.Behaviors>
                            </Controls:DoneEntry>
                        </RelativeLayout>                        
                    </StackLayout>
                </Frame>
                <Frame 
                    OutlineColor="Silver"
                    BackgroundColor="#FFFFFF"
                    VerticalOptions="FillAndExpand"
                    HasShadow="False" >
                    <StackLayout 
                            HorizontalOptions="FillAndExpand"
                            VerticalOptions="FillAndExpand"
                            BackgroundColor="Transparent">
                        <Editor 
                                Text="{Binding EmailContent}"
                                FontSize="Micro"
                                HorizontalOptions="FillAndExpand"
                                VerticalOptions="FillAndExpand"
                                 >
                            <CorcavBehaviors:Interaction.Behaviors>
                                <CorcavBehaviors:BehaviorCollection>
                                    <PounceBehaviors:EditorTextChanged Command="{Binding MessageTextChangedCommand}"/>
                                </CorcavBehaviors:BehaviorCollection>
                            </CorcavBehaviors:Interaction.Behaviors>
                        </Editor>
                    </StackLayout>
                </Frame>

            </StackLayout>


        <RelativeLayout
                Padding="5,5,5,5"
                RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=.12}"
                RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
                RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.88}"
                HorizontalOptions="CenterAndExpand"
                VerticalOptions="CenterAndExpand">

            <BoxView Color="#3E95D1" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" HeightRequest="1" />

            <Controls:SwipeRightButton x:Name="SendEmail_Button"
                    BackgroundColor="#2A84D3"
                    OutlineColor="Silver"
                    HasShadow="False"
                    RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
                    RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.90}" >

                <StackLayout x:Name="ImageLabelContainer"
                        RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
                        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.90}"
                        Orientation="Horizontal"
                        HorizontalOptions="CenterAndExpand">

                    <Image 
                            x:Name="connect_icon" 
                            Source="sendemailwhite"
                            Aspect="AspectFill"
                            BackgroundColor="Transparent"
                            VerticalOptions="Center"
                            HorizontalOptions="Center">
                    </Image>
                    <Label 
                            VerticalOptions="Center"
                            HorizontalOptions="Center" 
                            FontSize="Micro"
                            TextColor="#FFFFFF"
                            Text="Swipe to Send" />
                </StackLayout>
            </Controls:SwipeRightButton>
        </RelativeLayout>
    </RelativeLayout>

1 个答案:

答案 0 :(得分:0)

发现问题。第一帧&#39; VerticalOption应该是Start而不是StartAndExpand。