首页 > 解决方案 > 更改列表视图的高度

问题描述

所以我ListView在一个里面有 3 个,StackLayout但我得到了一个卷轴,ListView我希望它们的高度取决于包含的项目数量。

这是我的xaml文件

 <StackLayout>
            <StackLayout>
                <Label Text="Ingredientes"
               HorizontalOptions="CenterAndExpand">
                </Label>
                <ListView x:Name="listaIngredientes"
                      ItemsSource="{Binding ingredientes}"
                      VerticalOptions="FillAndExpand">
                </ListView>
            </StackLayout>



            <StackLayout>
                <Label Text="Informacion dietetica"
               HorizontalOptions="CenterAndExpand">

                </Label>
                <ListView x:Name="informacionDietetica"
                      ItemsSource="{Binding especificacionesDieteticas}"
                          VerticalOptions="FillAndExpand">
                </ListView>
            </StackLayout>



            <StackLayout>
                <Label Text="Informacion nutricional"
               HorizontalOptions="CenterAndExpand">
                </Label>
                <ListView x:Name="informacionNutricional"
                      ItemsSource="{Binding especificacionesSanitarias}"
                      VerticalOptions="FillAndExpand">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextCell Text="{Binding}">

                            </TextCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </StackLayout>

我试过把所有东西都包在里面ScrollViewAbsoluteLayoutRelativeLayout没有人成功。

标签: c#xamarin.forms

解决方案


这里有一个解决方案,你可以试一试。

如果可以确定其中的数量并设置每个的高度,则Cells可以计算出的高度。同时,程序运行时可以如下动态修改高度。ListViewCellListViewListView

listview.HeightRequest = CellCount * CellHeight;

例如:列表视图的高度listaIngredientes应该是:

listaIngredientes.HeightRequest == YourViewModel.ingredientes.Count * CellHeight;

推荐阅读