最后一行在ListView Xamarin表单中被截断

时间:2019-05-13 15:04:23

标签: forms listview xamarin xamarin.forms

我正在学习xamarin形式,到目前为止,我已经能够在论坛和Internet的帮助下取得进步,但是我为无法解决的问题感到难过。 总而言之,我有一个显示数据收集的Listview,并且我使用mvvm。 问题在于,在移动设备上查看时,最后一行被切断,并且页面底部的按钮也未显示。 我已经阅读了多个主题,并尝试了一些方法,但是没有任何效果。 PS:我无法确定固定的高度,它必须是动态的,具体取决于数据的大小。 我向您展示了部分代码,以查看是否可以帮助我。

谢谢。

<StackLayout Style = "{StaticResource whiteBody}">
            <FlexLayout Direction = "Column" VerticalOptions = "FillAndExpand">
                <Grid VerticalOptions = "FillAndExpand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height = "Auto" />
                        <RowDefinition Height = "Auto" />
                        <RowDefinition Height = "Auto" />
                        <RowDefinition Height = "Auto" />
                        <RowDefinition Height = "*" />
                    </ Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width = "Auto" />
                        <ColumnDefinition Width = "*" />
                    </Grid.ColumnDefinitions>

                    <StackLayout Grid.Column = "0" Grid.Row = "0" Grid.ColumnSpan = "2" Style = "{StaticResource redBar}">
                        <Label Style = "{StaticResource whiteText}" Text = "OFFER FINDER" HorizontalOptions = "StartAndExpand"
                                AutomationProperties.IsInAccessibleTree = "True"
                                AutomationProperties.HelpText = "My offers"
                                AutomationProperties.Name = "My offers" />
                        <Label Style = "{StaticResource whiteText}" Text = "MENU" x: Name = "menuLink" HorizontalOptions = "EndAndExpand"
                                AutomationProperties.IsInAccessibleTree = "True"
                                AutomationProperties.HelpText = "Back to menu"
                                AutomationProperties.Name = "Menu">
                            <! - <Label.GestureRecognizers>
                                    <TapGestureRecognizer Command = "{Binding NavigateCommand}" CommandParameter = "{x: Local Type: MenuView}"
                                        NumberOfTapsRequired = "1" />
                                </Label.GestureRecognizers> ->
                        </ Label>
                    </ StackLayout>

                    <StackLayout Grid.Column = "0" Grid.Row = "1" Grid.ColumnSpan = "2" Style = "{StaticResource backSave}">
                        <Label Style = "{StaticResource redText}" Text = "Return" HorizontalOptions = "StartAndExpand"
                                AutomationProperties.IsInAccessibleTree = "True"
                                AutomationProperties.HelpText = "Back to the offers search"
                                AutomationProperties.Name = "Back to search engine" />
                        <Label Style = "{StaticResource redText}" Text = "Save search" x: Name = "saveSearch" HorizontalOptions = "End"
                                AutomationProperties.IsInAccessibleTree = "True"
                                AutomationProperties.HelpText = "Save search"
                                AutomationProperties.Name = "Save search">
                            <! - <Label.GestureRecognizers>
                                    <TapGestureRecognizer Command = "{Binding NavigateCommand}" CommandParameter = "{x: Local Type: MenuView}"
                                        NumberOfTapsRequired = "1" />
                                </Label.GestureRecognizers> ->
                        </ Label>
                    </ StackLayout>
                    <FlexLayout Direction = "Column" Grid.Column = "0" Grid.Row = "2" Grid.ColumnSpan = "2" HeightRequest = "1">
                        <BoxView Style = "{StaticResource lineHorz}" AutomationProperties.IsInAccessibleTree = "False" />
                    </ FlexLayout>
                    <! - Square content ->
                        <ListView Grid.Column = "0" Grid.Row = "3" Grid.ColumnSpan = "2" HasUnevenRows = "True" ItemsSource = "{Binding DealsList}"
                                   x: Name = "OffersListView" SeparatorVisibility = "Default" HeightRequest = "1000">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell>
                                    <StackLayout Style = "{StaticResource resultStack}" VerticalOptions = "FillAndExpand">
                                            <StackLayout x: Name = "stackFavorites" Style = "{StaticResource favsStack}">
                                                <BoxView BackgroundColor = "Gray" HorizontalOptions = "Start" VerticalOptions = "Center"
                                                     HeightRequest = "45" WidthRequest = "45" Margin = "25,0,0,0"
                                                    AutomationProperties.IsInAccessibleTree = "False" />
                                                <Label Text = "{Binding stateFav}" VerticalOptions = "Center" Margin = "5"> </ Label>
                                                <StackLayout.GestureRecognizers>
                                                    <TapGestureRecognizer Command = "{Binding changeFav}" NumberOfTapsRequired = "1" />
                                                </StackLayout.GestureRecognizers>

1 个答案:

答案 0 :(得分:0)

您是否想获得像遵循GIF一样的结果?(我不知道您对每个控件的风格是什么,所以我将其删除)

enter image description here

如果要实现此目标,请像下面的代码一样在ScrollView外部包裹stacklayout。(我删除了listview的高度,可以根据内容调整高度)

    <ScrollView>
    <StackLayout>
        <FlexLayout  Direction = "Column" VerticalOptions = "FillAndExpand">
        <Grid VerticalOptions = "FillAndExpand">
            <!--5 行 2列 -->

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <StackLayout Grid.Column = "0" Grid.Row = "0" Grid.ColumnSpan = "2">
                <Label  Text = "OFFER FINDER" HorizontalOptions = "StartAndExpand"
                            AutomationProperties.IsInAccessibleTree = "True"
                            AutomationProperties.HelpText = "My offers"
                            AutomationProperties.Name = "My offers" />
                <Label  Text = "MENU" x:Name = "menuLink" HorizontalOptions = "EndAndExpand"
                            AutomationProperties.IsInAccessibleTree = "True"
                            AutomationProperties.HelpText = "Back to menu"
                            AutomationProperties.Name = "Menu">

                </Label>
            </StackLayout>

            <StackLayout Grid.Column = "0" Grid.Row = "1" Grid.ColumnSpan = "2" >
                <Label  Text = "Return" HorizontalOptions = "StartAndExpand"
                            AutomationProperties.IsInAccessibleTree = "True"
                            AutomationProperties.HelpText = "Back to the offers search"
                            AutomationProperties.Name = "Back to search engine" />
                <Label  Text = "Save search" x:Name = "saveSearch" HorizontalOptions = "End"
                            AutomationProperties.IsInAccessibleTree = "True"
                            AutomationProperties.HelpText = "Save search"
                            AutomationProperties.Name = "Save search">

                </Label>
            </StackLayout>

            <FlexLayout Direction = "Column" Grid.Column = "0" Grid.Row = "2" Grid.ColumnSpan = "2" HeightRequest = "1">
                <BoxView  AutomationProperties.IsInAccessibleTree = "False" />
            </FlexLayout>
            <!-- Square content -->
            <ListView Grid.Column = "0" Grid.Row = "3" Grid.ColumnSpan = "2" HasUnevenRows = "True" 
                               x:Name = "OffersListView" SeparatorVisibility = "Default" >
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout  VerticalOptions = "FillAndExpand">
                                <StackLayout x:Name = "stackFavorites" >
                                    <BoxView BackgroundColor = "Gray" HorizontalOptions = "Start" VerticalOptions = "Center"
                                                 HeightRequest = "45" WidthRequest = "45" Margin = "25,0,0,0"
                                                AutomationProperties.IsInAccessibleTree = "False" />
                                    <Label Text = "{Binding stateFav}" VerticalOptions = "Center" Margin = "5"></Label>
                                    <!--    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer Command = "{Binding changeFav}" NumberOfTapsRequired = "1" />
                                    </StackLayout.GestureRecognizers> -->
                                </StackLayout>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <StackLayout Grid.Column = "0" Grid.Row = "4" Grid.ColumnSpan = "2" >


                <Grid VerticalOptions = "FillAndExpand" >
                    <!--5 行 2列 -->

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Button  Text="Button1" Grid.Column = "0" Grid.Row = "0" />
                    <Button  Text="Button2"  Grid.Column = "1" Grid.Row = "0" />
                </Grid>
            </StackLayout>
        </Grid>
    </FlexLayout>
    </StackLayout>
</ScrollView>