【问题标题】:How to display image using xamarin in android project如何在android项目中使用xamarin显示图像
【发布时间】:2021-04-18 11:25:41
【问题描述】:

我尝试使用 xamarin 在 android 项目中显示图像。

  1. 我把文件夹Images放在我的android项目目录Resources/drawable/Images

  2. 我从BuildAction 设置了每个图像属性AndroidResource(我不确定是否应该这样)

  3. 在 c# 代码中,我尝试使用此代码调用图像,但对我不起作用:

     if (descriptionForecast1 == "clear sky")
                 {
                     ImageDescriptionForecast1.Source = "Images/ClearSky.jpg";
                     ImageForecast1.Source = "Images/ClearSky.jpg";
                 }
    

我能否获得一个如何调用图像的示例,因为我收到这样的错误,即路径错误:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Aapt2.targets(3,3): Error APT2144: invalid file path '/Users/pizhev/Projects/WeatherLocationInfo 0.0.1/WeatherLocationInfo.Android/obj/Debug/res/drawable/images/lightrain1.jpg'. (APT2144) (WeatherLocationInfo.Android)

【问题讨论】:

  • 查看文档local-images
  • 有没有办法像我在 iOS 项目中那样称呼他们?

标签: c# android xamarin


【解决方案1】:

来自docs

Android - 使用 Build 将图像放置在 Resources/drawable 目录中 行动:AndroidResource。图像的高和低 DPI 版本可以 也提供(在适当命名的资源子目录中,例如 作为drawable-ldpi、drawable-hdpi和drawable-xhdpi)。

不要在资源中创建自己的子文件夹

【讨论】:

  • 我会试试这个,并会就你的回答提供反馈:)
  • 为我工作!谢谢!
猜你喜欢
  • 2018-03-16
  • 1970-01-01
  • 1970-01-01
  • 2021-12-29
  • 2019-11-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多