Forum Xamarin.Forms

Image not showing/crashing app on some devices

leeyoleeyo USMember ✭✭
edited January 2018 in Xamarin.Forms

I've made an APK of my application to deploy it on a friend's Android device. Everything goes well but one image DOESN'T show on his device and it DOES show on my device and other friend's one (with same APK source file, of course).

Bugging device: Galaxy Note 3 with Android 5.0
Working devices: Oneplus 3 with Android 8.0 & Samsung A3 with Android 6.0.1
Android project: MinTarget=4.0.3 & compiled with Android 8.0

The code looks like this:

[Grid HorizontalOptions="Fill" VerticalOptions="Fill"]
[Image Source="{Binding Source={x:Static resources:ImagesIndex.Background}}" Aspect="AspectFill" /]
[StackLayout Orientation="Vertical" HorizontalOptions="Fill" VerticalOptions="Fill" Margin="10" Padding="10" BackgroundColor="#AAFFFFFF"]
// some content

(I couldn't use normal marking on the forum so I replaced marks by [ ])

Just so you know, the "{x:Static resources:ImagesIndex.Background}}" syntax is used for every other images and there is no problem with them. It points to a string "background.jpg" and this background file is located under AndroidProject/Resources/drawable as AndroidResource.

I've made some other tries:
- Removing the « BackgroundColor="#AAFFFFFF" » from child StackLayout but no difference
- Expanding the Image with HorizontalOptions & VerticalOptions as "Fill" but no difference
- Finally, I went to call this image in the background of parent page with « BackgroundImage="{x:Static resources:ImagesIndex.Background}}" » and the app went to crash after splashscreen on each run

One more thing: This "Grid" code (shown above) works on the bugging phone with a ScrollView in place of the StackLayout, so could the StackLayout be the cause of troubles even if this explanation still doesn't tell me why app is crashing with BackgroundImage applied on the parent page (ContentPage)?

Thanks for reading.


  • Eric_LiraEric_Lira USMember ✭✭✭

    Hi @leeyo.

    Just a quick question. Why are using Grid if you didn't put any controls inside it? Although Image and StackLayout are inside Grid tags, you still need to set Grid.Row and Grid.Column for them. Is it like that in your real XAML or you just left it out for in the post?

  • leeyoleeyo USMember ✭✭
    Hi @Eric_Lira,

    I'm using a Grid because this is the easier way to put a backgroundimage to a page with aspect controls. Visual elements will just overlap if put on same row/column, and that's of course my objective.

    As zero is the default value for row and column inside a Grid, there is no need to precise it since you only need to overlap one item to another.
  • Eric_LiraEric_Lira USMember ✭✭✭

    Hi @leeyo, OK got it.

    Are the other images jpg too? Can you try to copy one of the other images that are working and name as "background.jpg" just to see if the problem is the image it self?

  • leeyoleeyo USMember ✭✭

    Hi @Eric_Lira,

    I gave it some more tries :

    • I inversed the names of images for "background.jpg" and "splash-screen.jpg" (as this one works), the ex-background showed as it should on splash, but ex-splash didn't show on background so I guess the image-file isn't causing the issue;
    • I put the Grid's child "StackLayout" in a ContentView (as Grid's child) but no difference;

    I tried another app I made with same Grid principle on this "bugging device", background image didn't show either BUT it did in one case : this other app uses a MasterDetailPage, and in the master part I have this kind of Grid with an Image and a ScrollView as childs, and there the image is showing as it should.

    I'm really thinking of a Xamarin.Forms issue, but as it made no difference with a ContentView around the StackLayout (trick tried and mentionned above) I can't blame the StackLayout. The DetailPage of second app also uses a ScrollView as child and image won't show there so I just can't expect to be saved by a ScrollView.

  • FishDevFishDev USMember ✭✭

    Probably a bit of a long shot but try wrapping the Image by itself in an empty Grid. I know I've had some odd issues in the past with how Images are rendered in terms of size and doing that resolved it. Also, you might consider trying CachedImage from the FFImageLoading nuget package instead of the Xamarin.Forms image. It extends the forms Image so you can just use it in place of it. It's fixed some issues for me in the past as well (mostly related to memory, but who knows).

  • Eric_LiraEric_Lira USMember ✭✭✭

    @leeyo have you tested in other Android 5.0 device? Could be something related to that specific version.

  • leeyoleeyo USMember ✭✭

    Hi @FishDev,

    I tried two more builds :

    • StackLayout commented so I had a Grid with a single child (the Image) and it didn't show either
    • FFImageLoading with my usual build (Grid, Image & StackLayout) and it worked !

    So by now I know I should use this addon everywhere, hehe.

    Hi @Eric_Lira,

    I don't know many people who still use such an old phone, so I couldn't answer if the phone or the Android version is causing this issue...

    Anyway, thanks to you both for help, we finally went through this ! ;-)

Sign In or Register to comment.