【发布时间】:2020-02-03 18:15:36
【问题描述】:
我正在 Xamarin Visual Studio 2019 中开发 Cross-Platform 应用程序,但图像显示存在问题。
我正在尝试使用以下 XAML 代码显示图像。
<StackLayout Grid.Row="0" Grid.Column="0" Spacing="0" >
<Image
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Source="logo"
WidthRequest="{OnPlatform iOS=300, Android=250}">
</Image>
</StackLayout>
问题是image not displaying on either preview or deployed app。
我从多个论坛(包括 StackOverflow 的帮助)中获取了参考资料,但无法解决这个问题。
以下是我解决问题的要点和方法。
- 名为
logo的文件是一个android资源文件夹,是一个正确的.png文件。 - 文件的属性设置为
AndroidResource。 根据此处发布的答案Xamarin Images not showing,文件名中没有连字符,并且还在同一页面上尝试了其他发布的答案。
图像大小为 307X80 像素,因此在内存或大小范围内。
Android Drawable 文件夹还包含默认的xamarin_logo.png 图像,并且该文件可以正常工作。但不是新添加的图像。将这些图像文件添加到解决方案中时,我在这里缺少什么吗?
【问题讨论】:
标签: xamarin xamarin.forms xamarin.android xamarin.ios visual-studio-2019