2

When I run my app on an iphone, all the images come up great. But when I tried running it on an android, none of the images showed up at all. The images were placed in both the ios and android folders (Android/Resources/drawable).

Anyone know why the images don't appear on an android?

user3841879
  • 659
  • 3
  • 12
  • 21
  • Do you have any code and/or xaml for us to look at? I'm sure it's the comma in the third line that messes things up – Sten Petrov Aug 06 '14 at 14:18
  • See the following answer: https://stackoverflow.com/questions/1077357/can-the-android-drawable-directory-contain-subdirectories – Stuart Clement Apr 02 '18 at 15:33

2 Answers2

0

I solved this exact problem by loading the images in the code behind.

henon
  • 2,022
  • 21
  • 23
0

The only way downloaded or filesystem retrieved images outside of the projects namespace work in Xamarin.Forms for Android is in the codebehind. Binding to the ImageSource will not display them. The problem has something to do with OnAppearing never setting or refreshing the property even if you set WidthRequest and HeightRequest. I'm actually not sure why but I have tested this process for a couple of weeks with no success. What I mean by this is the ViewModel is where you retrieve the image from a WebService or from the Filesystem then get and set your ImageSource this code typically will run on creation of the ViewModel or OnAppearing. There is a bug in the system with XAML so it will never work. Using the Codebehind and setting it directly is the only way the images will display. I don't know why this behaves this way but I have tested every conceivable way to do this and it does not work with ImageCircle or Image whether you set the ImageSource.FromFile or ImageSource.FromStream. It does work when you set the ImageSource in the XAMLs code behind using the Image object directly. If you read through this article on Images in Xamarin Forms it will explain which ways you can use XAML and display the the images using Embedded Resources and using.

https://developer.xamarin.com/guides/xamarin-forms/working-with/images/

    <Image Source="{local:ImageResource WorkingWithImages.beach.jpg}" /> 

The only runtime ImageSource binding that seems to work is using a web address and pulling from the URI.

<Image Source="https://xamarin.com/content/images/pages/forms/example-app.png" />
Mark Lane
  • 214
  • 3
  • 9