【问题标题】:Xamarin.Forms: calculating listview height wrong?Xamarin.Forms:计算列表视图高度错误?
【发布时间】:2019-07-20 15:51:39
【问题描述】:

为什么底部的标签中只显示了一半的文字?

这是我的xaml。 listview区域300个,listview每行100个(设置在<On Platform="Android">100</On>)。

每个ViewCell 有 4 行,每行 25 行,总共 100(listview 行高)。

所以我不明白为什么只显示底部的一半文本,或者为什么第 2 列的第 0 行和第 1 行占用的空间不完全是总高度的一半。

<Grid RowSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="100" />
        <RowDefinition Height="300" />
    </Grid.RowDefinitions>
    <StackLayout Grid.Row="0" x:Name="MapGrid">
        <maps:Map WidthRequest="960" HeightRequest="100" 
              x:Name="MyMap" IsShowingUser="true"/>
    </StackLayout>
    <StackLayout Grid.Row="1" x:Name="listSection" HeightRequest="300">
        <ListView x:Name="ListView_Pets">
            <ListView.RowHeight>
                <OnPlatform x:TypeArguments="x:Int32">
                    <On Platform="Android">100</On>
                </OnPlatform>
            </ListView.RowHeight>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="25"></RowDefinition>
                                <RowDefinition Height="25"></RowDefinition>
                                <RowDefinition Height="25"></RowDefinition>
                                <RowDefinition Height="25"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50*" />
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                            </Grid.ColumnDefinitions>
                            <Label Text="Name" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="15" TextColor="Black" Grid.Row="0" Grid.Column="0"/>
                            <Label Text="Address" HorizontalTextAlignment="Center" VerticalTextAlignment="Start" FontSize="10" TextColor="Black" Grid.Row="1" Grid.Column="0"/>
                            <Label Text="Price1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="15" TextColor="White" BackgroundColor="#2FA4D9" Grid.Row="0" Grid.Column="2"/>
                            <Label Text="Price2" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="15" TextColor="White" BackgroundColor="#2FA4D9" Grid.Row="1" Grid.Column="2"/>
                            <Label Text="Tag1" Grid.Row="0" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Grid.Column="1" FontSize="Micro"/>
                            <Label Text="Tag2" Grid.Row="1" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Grid.Column="1" FontSize="Micro"/>
                            <StackLayout Grid.Row="3" Grid.Column="0">
                                <StackLayout Orientation="Horizontal" >
                                    <Label Text="Text1" FontSize="10" VerticalTextAlignment="Start" TextColor="Black" />
                                    <Label Text="Text2" VerticalTextAlignment="Start" FontSize="10" TextColor="Black" />
                                    <Label Text="Text3" VerticalTextAlignment="Start" FontSize="10" TextColor="Black" />
                                </StackLayout>
                            </StackLayout>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</Grid>

截图如下:

【问题讨论】:

    标签: xamarin xamarin.forms visual-studio-2017 xamarin.forms.listview


    【解决方案1】:

    这是因为 ViewCell 中的 Grid 具有 RowSpacing 和 ColumnSpacing 默认值。要覆盖它,只需设置&lt;Grid RowSpacing=0 ColumnSpacing=0&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多