删除不需要的白色间距

时间:2020-02-19 12:15:20

标签: xaml xamarin.forms

我有一个视图,其中有2个Listview的视图用于显示总发票,而一个视图则包含了发票中所有项目的详细信息(购物车项目)

您会注意到,在主订单和物料清单之间有巨大的空白,我似乎无法摆脱间距,而没有设置我想避免的硬值。有人知道吗?

Listview是否只是占用了另一个项目的空间,但可能只包含一个项目?

仅需详细说明一下,我可以给顶部的Listview一个HeightRequest,让它说310左右来获得正确的间距,但是我正在寻找一种不需要设置的方式。可能会在某些手机上扭曲的硬值

  <ContentPage.Content>
        <StackLayout BackgroundColor="Transparent" Spacing="0" Opacity="1" HorizontalOptions="FillAndExpand"
                     Margin="4,0,4,0" VerticalOptions="StartAndExpand">
            <Label Text="Main Order" TextColor="White" HeightRequest="30" HorizontalOptions="Center"
                   VerticalOptions="Center" FontSize="Title" FontAttributes="Bold" />

            <ListView x:Name="SingleOrderList"
                      BackgroundColor="Transparent"
                      HasUnevenRows="True"

                      VerticalOptions="Start"
                      HorizontalOptions="FillAndExpand"
                      SeparatorVisibility="Default">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.View>
                                <Frame CornerRadius="20" BackgroundColor="White" Margin="4,0,4,0" Padding="27">
                                    <StackLayout BackgroundColor="Transparent" Orientation="Vertical" Spacing="0">


                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>
                                                    <Span Text="ID:" FontAttributes="Bold" FontSize="Large" />
                                                    <Span Text="{ Binding id }" FontAttributes="Bold" FontSize="Large" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>
                                                    <Span Text="Mail:" />
                                                    <Span Text="{ Binding billing.email }" FontAttributes="Bold"
                                                          FontSize="Medium" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>
                                                    <Span Text="Date:" />
                                                    <Span Text="{ Binding date_created }" FontAttributes="Bold"
                                                          FontSize="Medium" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>
                                                    <Span Text="Status:" />
                                                    <Span Text="{ Binding status }" FontAttributes="Bold"
                                                          FontSize="Medium" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>

                                                    <Span Text="{ Binding total, StringFormat='Total R:{0,5:#,0.00}' }"
                                                          FontAttributes="Bold" FontSize="Medium" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                    </StackLayout>
                                </Frame>
                            </ViewCell.View>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <Label Text="ITEMS" TextColor="White" HeightRequest="30" HorizontalOptions="Center"
                   VerticalOptions="Center" FontSize="Title" FontAttributes="Bold" />
            <ListView BackgroundColor="Transparent"
                      x:Name="Lineorders"
                      HasUnevenRows="True"
                      VerticalOptions="FillAndExpand"
                      HorizontalOptions="FillAndExpand"
                      SeparatorVisibility="Default">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.View>
                                <Frame CornerRadius="20" BackgroundColor="White" Margin="10" Padding="20">
                                    <StackLayout
                                        Spacing="0"
                                        BackgroundColor="Transparent"
                                        VerticalOptions="FillAndExpand"
                                        HorizontalOptions="FillAndExpand">
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>
                                                    <Span Text="Product:" FontAttributes="Bold" FontSize="Large" />
                                                    <Span Text="{ Binding name }" FontAttributes="Bold"
                                                          FontSize="Large" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>
                                                    <Span Text="Price:" />
                                                    <Span
                                                        Text="{ Binding price,StringFormat={}{0:0.####################}}"
                                                        FontAttributes="Bold" FontSize="Medium" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>
                                                    <Span Text="Sku:" />
                                                    <Span Text="{ Binding sku }" FontAttributes="Bold"
                                                          FontSize="Medium" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>

                                                    <Span
                                                        Text="{ Binding total , StringFormat='Total R:{0,5:#,0.00}' }"
                                                        FontAttributes="Bold" FontSize="Medium" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                        <Label HorizontalTextAlignment="Center" TextColor="Black">
                                            <Label.FormattedText>
                                                <FormattedString>
                                                    <Span Text="Quantity:" />
                                                    <Span Text="{ Binding quantity }" FontAttributes="Bold"
                                                          FontSize="Medium" />
                                                </FormattedString>
                                            </Label.FormattedText>
                                        </Label>
                                    </StackLayout>
                                </Frame>
                            </ViewCell.View>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
    </ContentPage.Content>

enter image description here

在没有HeightRequest的情况下我正在寻找什么

enter image description here

1 个答案:

答案 0 :(得分:0)

enter image description here

<ContentPage.Content>
            <StackLayout
                Margin="4,0,4,0"
                BackgroundColor="Transparent"
                HorizontalOptions="FillAndExpand"
                Opacity="1"
                Spacing="0"
                VerticalOptions="StartAndExpand">
                <Label
                    FontAttributes="Bold"
                    FontSize="Title"
                    HeightRequest="30"
                    HorizontalOptions="Center"
                    Text="Main Order"
                    TextColor="White"
                    VerticalOptions="Center" />

                <ListView
                    x:Name="SingleOrderList"
                    BackgroundColor="Transparent"
                    HasUnevenRows="True"
                    HorizontalOptions="FillAndExpand"
                    SeparatorVisibility="Default"
                    VerticalOptions="FillAndExpand">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <ViewCell.View>
                                    <Frame
                                        Margin="4,0,4,0"
                                        Padding="5,10,5,5"
                                        BackgroundColor="White"
                                        CornerRadius="20">
                                        <StackLayout
                                            BackgroundColor="LightSeaGreen"
                                            Orientation="Vertical"
                                            Spacing="0">
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Large"
                                                            Text="ID:" />
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Large"
                                                            Text="23" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span Text="Mail:" />
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Medium"
                                                            Text="{Binding billing.email}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span Text="Date:" />
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Medium"
                                                            Text="{Binding date_created}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span Text="Status:" />
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Medium"
                                                            Text="{Binding status}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>

                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Medium"
                                                            Text="{Binding total, StringFormat='Total R:{0,5:#,0.00}'}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                        </StackLayout>
                                    </Frame>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
                <Label
                    FontAttributes="Bold"
                    FontSize="Title"
                    HeightRequest="30"
                    HorizontalOptions="Center"
                    Text="ITEMS"
                    TextColor="Black"
                    VerticalOptions="Center" />
                <ListView
                    x:Name="Lineorders"
                    BackgroundColor="Transparent"
                    HasUnevenRows="True"
                    HorizontalOptions="FillAndExpand"
                    SeparatorVisibility="Default"
                    VerticalOptions="FillAndExpand">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <ViewCell.View>
                                    <Frame
                                        Margin="10"
                                        Padding="5,10,5,5"
                                        BackgroundColor="White"
                                        CornerRadius="20">
                                        <StackLayout
                                            BackgroundColor="Red"
                                            HorizontalOptions="FillAndExpand"
                                            Spacing="0"
                                            VerticalOptions="FillAndExpand">
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Large"
                                                            Text="Product:" />
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Large"
                                                            Text="{Binding name}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span Text="Price:" />
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Medium"
                                                            Text="{Binding price, StringFormat={}{0:0.####################}}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span Text="Sku:" />
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Medium"
                                                            Text="{Binding sku}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>

                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Medium"
                                                            Text="{Binding total, StringFormat='Total R:{0,5:#,0.00}'}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                            <Label HorizontalTextAlignment="Center" TextColor="Black">
                                                <Label.FormattedText>
                                                    <FormattedString>
                                                        <Span Text="Quantity:" />
                                                        <Span
                                                            FontAttributes="Bold"
                                                            FontSize="Medium"
                                                            Text="{Binding quantity}" />
                                                    </FormattedString>
                                                </Label.FormattedText>
                                            </Label>
                                        </StackLayout>
                                    </Frame>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </ContentPage.Content>