3

Is it possible to organize my images in subfolders? Something like this example.

Android Project:

·Drawable
   ·navbarIcons
       -user.png
       -stats.png
   ·statsImages
       -goals.png
       -assists.png

iOS Project:

·Resources
   ·navbarIcons
       -user.png
       -stats.png
   ·statsImages
       -goals.png
       -assists.png

Or is it mandatory to let them on the Drawable/Resources folder?

  • 1
    See the following answer: https://stackoverflow.com/questions/1077357/can-the-android-drawable-directory-contain-subdirectories – Stuart Clement Apr 02 '18 at 15:35

1 Answers1

4

Its definitely possible to create subfolders on iOS. Also ensure that your casing is correct because they are case-sensitive and that your Build Actions are set up correctly.

UPDATE: As you can see its possible to add them in subfolders. Don't forget to add your images in the correct sizes such as 2x and 3x for iOS as I did below.

Definitely possible to add an image

UPDATE 2: Another thing you could do is put the images in your Shared PCL project and go the embedded images route. I believe this route doesn't give you as much flexibility when it comes to DPIs though:

https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Embedded_Images

Steven Thewissen
  • 2,971
  • 17
  • 23
  • Thanks @Steven but in my example, I'm creating an image with `Source="statsImages/assists.png"`and the image never appears. I have **AndroidResource** and **BundleResource** respectively and I've tried with backward slash too... Probably I'm missing something, could you help me? – Helio Ojeda Reyes May 15 '17 at 07:31
  • I updated my answer to show you how I've set it up. It is definitely possible. Perhaps your problem lies in the fact that you're not supplying the images in the resolutions the device/simulator looks for? – Steven Thewissen May 15 '17 at 07:49
  • I think it's not the problem @Steven because the image works perfectly when it's in the Drawable and Resources folder. Moving it to a new subfolder and change the Source properly is what is causing me the problem. – Helio Ojeda Reyes May 15 '17 at 08:04
  • Could you upload a small project with this issue to somewhere I could look at it? (e.g. Github) – Steven Thewissen May 15 '17 at 08:07
  • Thanks for your time @Steven. Although I've just checked that it works perfectly on iOS, I've been reading from different sources and it seems like Android doesn't allow having subfolders inside Drawable folder so I guess that organizing cross-platform images in subfolders are not possible. – Helio Ojeda Reyes May 15 '17 at 08:46
  • You could take a look at Embedded Images which lets you put the images in your shared/PCL library. Check my updated answer. – Steven Thewissen May 15 '17 at 08:56