Ben Johnson
Ben Johnson

Reputation: 985

How to display image using xamarin in android project

I trying to display a images in android project using xamarin.

  1. I put folder Images in my android project in directory Resources/drawable/Images

  2. I set on every image property AndroidResource from BuildAction (I'm not sure if that should be the case)

  3. In the c# code I try to call the image with this code but not worked for me:

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

Can I get an example of how to call the Images, because I get an error like this that the path is wrong:

/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)

Upvotes: 0

Views: 336

Answers (1)

Jason
Jason

Reputation: 89102

from the docs

Android - Place images in the Resources/drawable directory with Build Action: AndroidResource. High- and low-DPI versions of an image can also be supplied (in appropriately named Resources subdirectories such as drawable-ldpi, drawable-hdpi, and drawable-xhdpi).

do not create your own sub-folders in Resources

Upvotes: 1

Related Questions