【问题标题】:Xamarin Forms Image AspectFill isn't working correctlyXamarin Forms Image AspectFill 无法正常工作
【发布时间】:2021-08-07 20:35:25
【问题描述】:

谁能告诉我为什么这张图片没有填满屏幕? Android 模拟器上的“AspectFill”是否存在已知错误?

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="HelloWorld2.AbsoluteLayout_Exercise2">
    <AbsoluteLayout>
        <Image Source="AbsoluteLayout_Exercise2.jpeg" `Aspect="AspectFill"/>
    </AbsoluteLayout>
</ContentPage>

【问题讨论】:

  • Aspect 指定图像数据将如何填充图像控件。如果希望 Image 控件填满屏幕,请使用 Horizo​​ntalOptions 和 VerticalOptions
  • 谢谢杰森!这是我一直没有考虑到的那些时刻之一。发布后几分钟我自己解决了。

标签: c# xamarin xamarin.forms xamarin.android


【解决方案1】:

我需要利用 AbsoluteLayout.LayoutBounds 来缩放图像。我现在得到了想要的结果。

    <AbsoluteLayout VerticalOptions="FillAndExpand">
    <Image Source="AbsoluteLayout_Exercise2.jpeg" Aspect="AspectFill" 
           AbsoluteLayout.LayoutBounds="1,1,1,1"
           AbsoluteLayout.LayoutFlags="All"/>
    </AbsoluteLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-21
    • 2021-03-25
    • 2021-06-25
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-04
    相关资源
    最近更新 更多