android drawable import problem

hi community!

i have the following problem:

  1. ofcourse i tried some examples - in my case the Xamarin.Forms Gallery
  2. so far everything worked - i created my own ContentPage in the sharedcode App constructor and played around with the different views.
  3. i also added a child of type Image which worked well

grid.Children.Add(new Image { Source = Device.OnPlatform(ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png")), ImageSource.FromFile("ide_xamarin_studio.png"), ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png"))), VerticalOptions = LayoutOptions.CenterAndExpand }, 0, 1);

  1. remember the second case of Device.OnPlatform is Android - ImageSource.FromFile("ide_xamarin_studio.png") i builded and ran it on android and ios and it WORKED WELL!

  2. then i thought it might be nice to have a background image directly on the page. so i created something like this:

public App () { LNZMainView mView = new LNZMainView(); mView.BackgroundImage = "bgnd.png"; mView.Init (); MainPage = mView; }

  1. and then added the bgnd.png to the FormsGallery.Android -> Resources -> drawable-hdpi the same place as the ide_xamarin_studio.png used above at
    ImageSource.FromFile("ide_xamarin_studio.png"). Aswell as directly into the ForumsGallery.iOS -> Resources Folder.

  2. i copied the file there (not linking or moving) and checked for buildaction which was allready set to AndroidResource on Android / BundleResource on iOS. I checked the Resource.Designer.cs and there is a new entry called bgnd with a integer id.

  3. Clean -> Rebuild -> Run for Android now was crashing.

  4. So i tried on iOS and everything worked. So i uncommented the "mView.BackgroundImage = "bgnd.png";" line - still crashing. Then i uncommented the use of the Image and it worked again.

grid.Children.Add(new Image { Source = Device.OnPlatform(ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png")), ImageSource.FromFile("ide_xamarin_studio.png"), ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png"))), VerticalOptions = LayoutOptions.CenterAndExpand }, 0, 1);

  1. so the problems are:
    a. loading from resources worked on android for ImageSource before i manually imported a file to the drawable-hdpi
    b. mView.BackgroundImage = "bgnd.png" doesn't work at all (i'm not sure about the path)

Can someone help me? Any Idea whats going wrong?

Cheers,
O

Answers

  • rudi.2085rudi.2085 USMember

    Fixed by removing the complete resources folder from the android part of the project and reimport it. seems to be a little bug in the IDE's "importer".

Sign In or Register to comment.