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

如何让Grid内的Label最小化且最多显示两行?

Grid内嵌Label的布局需求及当前实现

需求

  • Grid与Label的尺寸尽可能小
  • Label必要时最多显示两行

当前实现代码

<VerticalStackLayout Spacing="8">
    <Label Text='With HorizontalOptions="Start":' />
        
    <Grid BackgroundColor="#FCC" HorizontalOptions="Start">
        <Label
                Text="This will not wrap."
                MaxLines="2"
                />
    </Grid>

    <Grid BackgroundColor="#FCC" HorizontalOptions="Start">
        <Label
                Text="This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. "
                MaxLines="2"
                />
    </Grid>

    <Label Text='With HorizontalOptions="Fill":' />

    <Grid BackgroundColor="#CFC" HorizontalOptions="Fill">
        <Label
                Text="This wraps, but fills."
                MaxLines="2"
                />
    </Grid>

    <Grid BackgroundColor="#CFC" HorizontalOptions="Fill">
        <Label
                Text="This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills."
                MaxLines="2"
                />
    </Grid>
</VerticalStackLayout>

当前效果

布局效果展示

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 01:25:37