首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin中的ListView inside StackLayout不会基于列表视图项目高度进行扩展

Xamarin中的ListView inside StackLayout不会基于列表视图项目高度进行扩展
EN

Stack Overflow用户
提问于 2020-01-01 01:44:27
回答 1查看 705关注 0票数 1

我有一个关于Xamarin StackLayout和ListView的问题。

我在StackLayout中使用Listview。Listview包含10个项目,它们很容易超出堆栈布局高度。我使用了Orientation作为Vertical,使用VerticalOptions作为StackLayout的FillAndExpand。当没有导航标题栏时,StackLayout会得到正确的扩展。问题是,当有导航标题栏时,Stacklayout不能正确扩展,Listview项目会缩小。还有其他人面临这个问题吗?

代码语言:javascript
复制
<ContentPage.Content>
        <StackLayout>    
            <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
                <ListView
                  HasUnevenRows="True"  
                  ItemsSource="{Binding sampleList}"
                  CachingStrategy="RecycleElement">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                              <views:sampleView/>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>         
        </StackLayout>        
</ContentPage.Content>   

我已经尝试了下面提到的选项。

代码语言:javascript
复制
 1) Setting the Height Request to parent Stack Layout. 
代码语言:javascript
复制
         It worked for some devices and not worked for some devices. 
代码语言:javascript
复制
 2) Use Grid instead of StackLayout by setting the Grid row definitions like given below.                         `<Grid.RowDefinitions>                 <RowDefinition Height="*"></RowDefinition>             </Grid.RowDefinitions>`              But this change also didn't fix the issue.
代码语言:javascript
复制
 3) Use Scroll View instead of StackLayout 
代码语言:javascript
复制
         This will work. But Xamarin suggests we should not nest ScrollView with other controls that provide scrolling, like ListView and WebView.         ( [https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scroll-view](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scroll-view) )
EN

回答 1

Stack Overflow用户

发布于 2020-08-11 09:34:53

我遇到了同样的问题,老实说我不知道原因,但在我的例子中,我不得不删除stackLayout,并将列表视图保留在ContentPage中。

我想更具体地说明原因,但我只是想知道如果有更多关于它的信息,我会让你知道的。

代码语言:javascript
复制
<ContentPage.Content>
    <ListView
        HasUnevenRows="True"  
        ItemsSource="{Binding sampleList}"
        CachingStrategy="RecycleElement">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <views:sampleView/>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage.Content>  
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59547093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档