【问题标题】:Xamarin.forms Image in emulator but not on device. (android)Xamarin.forms Image 在模拟器中但不在设备上。 (安卓)
【发布时间】:2018-03-26 07:54:42
【问题描述】:

我正在 xamarin.forms 中制作一个简单的应用程序。它会做一些事情,但我现在面临的问题是我有一张想要在启动时显示的图像。

它可以在 Android 模拟器上运行,但不能在实际的 android 设备上运行。 (我的手机)

我要呈现的图像是本地图像,它同时位于“Mobile/Resources/Drawable/image.png”和“Mobile.Android/Resources/Drawable/image.png”中

它们也是属性中正确的资源设置:“Embedded Resource”和“AndroidResource”。

为什么它不起作用?应用启动,但图像不存在。

编辑:

我的 xaml 看起来像这样:

<StackLayout
    Orientation="Vertical"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand">
    <Image Source="MainPage.png" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
</StackLayout>

【问题讨论】:

  • 嗨,我的回答对你有用吗?

标签: android mobile xamarin.forms android-emulator


【解决方案1】:

图片资源有两种使用方式,Local ImagesEmbedded Images。您可以在项目中选择一个。

1) 你可以使用Local Images:

<Image Source="image.png" 
       HorizontalOptions="FillAndExpand"
       VerticalOptions="FillAndExpand" />

2)你可以使用 Embedded Images,你不需要把你的image.png放到“Mobile/Resources/Drawable/image.png”路径,像android平台一样。你可以把它复制到“Moblie/image.png”,然后像这样使用它:

<Image Source="{local:ImageResource Moblie.image.png}
       HorizontalOptions="FillAndExpand"
       VerticalOptions="FillAndExpand" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 2020-01-01
    相关资源
    最近更新 更多