【问题标题】:Xamarin Grid Height changes after Images Loaded加载图像后 Xamarin 网格高度发生变化
【发布时间】:2021-04-04 10:25:43
【问题描述】:

正如我在附加图像中显示的那样,在连接到服务器并加载图像之前,我的网格行是方形空间,但是当加载图像时,它会改变它的高度并变成矩形。我怎样才能避免它?我想保留方形空间。

我的照片也是方形的。

连接服务器前后 [1]:https://i.stack.imgur.com/lZj6F.png [2]:https://i.stack.imgur.com/ZaKQd.png

代码:

                        <Image x:Name="imgStation1" Grid.Row="0" Grid.Column="0" BackgroundColor="White" Source="saturday.jpg"  Aspect="AspectFill" />
                        <StackLayout Grid.Row="0" Grid.Column="0" VerticalOptions="StartAndExpand" Spacing="10" Margin="10">
                            <Label x:Name="lblLiveStation1"  Text="" FontSize="Small" TextColor="AntiqueWhite">
                                <Label.FontFamily>
                                    <OnPlatform
                         x:TypeArguments="x:String"
                         Android="gothic.ttf#gothic"
                         iOS="Optima-Regular" />
                                </Label.FontFamily>
                            </Label>
                            <Label x:Name="lblDescriptionStation1"  Text="Loading..." FontSize="Medium" FontAttributes="Bold" TextColor="FloralWhite">
                                <Label.FontFamily>
                                    <OnPlatform
                         x:TypeArguments="x:String"
                         Android="gothic.ttf#gothic"
                         iOS="Optima-Regular" />
                                </Label.FontFamily>
                            </Label>
                            <Label x:Name="lblTimeStation1"  Text="" FontSize="Small" FontAttributes="Bold" TextColor="GhostWhite">
                                <Label.FontFamily>
                                    <OnPlatform
                         x:TypeArguments="x:String"
                         Android="gothic.ttf#gothic"
                         iOS="Optima-Regular" />
                                </Label.FontFamily>
                            </Label>
                            <ImageButton x:Name="imgPlayPause0" Grid.Row="0" VerticalOptions="End" HorizontalOptions="Start" Source="playlogo.png" BackgroundColor="Transparent" Clicked="imgPlayPause0_Clicked"></ImageButton>
                        </StackLayout>
 </StackLayout>

【问题讨论】:

    标签: xamarin grid


    【解决方案1】:

    你试过给Aspect="Fill"吗?

    如果您想要高度 = 宽度(即方形)的图像,则为其提供硬编码的宽度或高度。

    如果这在您的情况下是不可能的,那么请尝试使用RelativeSource,其中WidthHeight ="*" 和高度将相对于宽度,就像这样WidthRequest="{Binding Source={x:Reference Self}, Path=WidthRequest}}"

    【讨论】:

    • 感谢 Heightrequest 完成了这项工作。 Aspect=Fill 并不能解决它只是在小矩形空间上拉伸我的图像的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    • 2016-03-02
    • 1970-01-01
    • 2020-10-18
    • 2012-03-08
    • 2015-12-16
    相关资源
    最近更新 更多