【问题标题】:How to set ListView At the end of page如何在页面末尾设置 ListView
【发布时间】:2020-05-23 11:24:08
【问题描述】:

我已经使用了 VerticalOptions="EndAndExpand" 然后还在最后留下了空间,任何人对此都有想法。 我已经在我面临的同样问题中尝试了集合视图

<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
         <ffimageloading:CachedImage Margin="10" x:Name="ImageData"
                         IsVisible="{Binding IsImageURL}"
                         IsEnabled="{Binding IsImageURL}"
                         Source="{Binding ImageURL}"
                         HeightRequest="150" WidthRequest="200"
                         HorizontalOptions="CenterAndExpand"
                         VerticalOptions="CenterAndExpand"
                         BackgroundColor="Transparent" Aspect="Fill" >
         </ffimageloading:CachedImage>

         <ListView x:Name="QuizzesAnsList" BackgroundColor="Blue"
                      ios:ListView.RowAnimationsEnabled="false"
                      VerticalOptions="EndAndExpand"
                      HorizontalOptions="FillAndExpand"
                      SelectionMode="None"
                      VerticalScrollBarVisibility="Never"
                      HasUnevenRows="True"
                      ItemsSource="{Binding QuizzesQuestionAnswersList}"
                      SeparatorVisibility="None" >
                    <ListView.ItemTemplate >
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout VerticalOptions="Fill" Orientation="Horizontal" Spacing="0" Margin="0,5,0,0">

                                    <Frame  VerticalOptions="Fill" BackgroundColor="{Binding BackgroundColor}" BorderColor="{Binding BorderColor}" HasShadow="False"  HorizontalOptions="FillAndExpand"  CornerRadius="2"  Padding="5" >
                                        <StackLayout Orientation="Horizontal" Spacing="0" VerticalOptions="Fill" HorizontalOptions="FillAndExpand" >
                                            <material:MaterialLabel Margin="5" Text="{Binding AnswerText}" HorizontalTextAlignment="Center" FontSize="17" Style="{Binding FontType,Mode=TwoWay}"                                                                  VerticalTextAlignment="Center" HorizontalOptions="FillAndExpand" TextColor="White" FontAttributes="Bold" />
                                        </StackLayout>
                                    </Frame>

                                    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer
                                                            Command="{Binding Path=BindingContext.SelectedQuizeAnswer, Source={x:Reference QuizzesAnsList}}"
                                                            CommandParameter="{Binding .}"/>
                                    </StackLayout.GestureRecognizers>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
         </ListView>
</StackLayout>

【问题讨论】:

  • 请提供一些您问题的重要部分的代码示例,我们无法调试我们看不到的代码
  • 是的,当然@RicardoDiasMorais
  • 您好,我在您的代码中发现了问题。您列出静态或动态的项目
  • 我猜如果你的 StackLayout 包装了整个页面内容,你应该添加另一个包含图像和列表视图的堆栈,然后 StackLayout 应该在 VerticalOptions 上有 End,所以列表和图片
  • 另外请记住,如果您的列表视图上没有足够的项目,当然您将拥有该空间,列表视图不会“扩展”您拥有的项目越多,它是可滚动的布局

标签: listview xamarin xamarin.forms prism stacklayout


【解决方案1】:

我在您的代码中发现了问题。实际上,ListView 占据了整个页面。如果您的列表项是静态的,则您在ListView 中设置HeightRequest="100" 或者您的列表项是动态使用BindableLayout

<StackLayout x:Name="QuizzesAnsList" BindableLayout.ItemsSource="{Binding QuizzesQuestionAnswersList}"  VerticalOptions="EndAndExpand" HorizontalOptions="FillAndExpand">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <StackLayout VerticalOptions="Fill" Orientation="Horizontal" Spacing="0" Margin="0,5,0,0">
                                    <Frame  VerticalOptions="Fill" BackgroundColor="{Binding BackgroundColor}" BorderColor="{Binding BorderColor}" HasShadow="False"  HorizontalOptions="FillAndExpand"  CornerRadius="2"  Padding="5" >
                                        <StackLayout Orientation="Horizontal" Spacing="0" VerticalOptions="Fill" HorizontalOptions="FillAndExpand" >

                                            <material:MaterialLabel Margin="5" Text="{Binding AnswerText}" HorizontalTextAlignment="Center" FontSize="17" Style="{Binding FontType,Mode=TwoWay}"
                                                                        VerticalTextAlignment="Center" HorizontalOptions="FillAndExpand" TextColor="White" FontAttributes="Bold" />
                                        </StackLayout>

                                    </Frame>

                                    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer
                                                            Command="{Binding Path=BindingContext.SelectedQuizeAnswer, Source={x:Reference QuizzesAnsList}}"
                                                            CommandParameter="{Binding .}"/>
                                    </StackLayout.GestureRecognizers>
                                </StackLayout>

                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>

【讨论】:

  • 如果我当时只绑定两个答案如何增加 Box 的高度,我需要更多帮助。 prnt.sc/r02uns
  • 设置HeightRequestViewCell里面的StackLayout
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多