You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin.Forms ListView内嵌Grid行高固定图片截断问题求助

问题原因

两处配置错误导致行高固定、图片被截断:

  1. ListView的HasUnevenRows属性被设置为False,该属性为False时所有列表行会使用统一固定高度,不会根据内容自动调整。
  2. Grid的行高被硬编码为固定值169,直接限制了行的最大高度,高度超过169的内容会被截断。

修改方案

按以下步骤调整XAML配置即可实现行高自适应:

  • 第一步:修改ListView属性,将HasUnevenRows="False"改为HasUnevenRows="True",开启行高自适应能力。
  • 第二步:修改Grid的行定义,将<RowDefinition Height="169"></RowDefinition>改为<RowDefinition Height="Auto"></RowDefinition>,让行高根据内部内容自动计算。
  • 可选优化:将Grid第一列的固定宽度<ColumnDefinition Width="347"></ColumnDefinition>改为<ColumnDefinition Width="*"></ColumnDefinition>,适配不同设备的屏幕宽度,避免图片横向被截断。

修改后的核心代码片段参考:

<!-- 修改后的ListView配置 -->
<ListView x:Name="ltvArquivoLista" SeparatorVisibility="None" SelectionMode="None" HasUnevenRows="True" IsPullToRefreshEnabled = "True">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid BackgroundColor="Transparent">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="40"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <!-- 其余内部控件配置保持不变 -->
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

内容的提问来源于stack exchange,提问作者Marcelo Camarate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 16:36:00