Hi,
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
[/StackLayout]
[/Grid]
(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.
0
Posts
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?
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.
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?
Hi @Eric_Lira,
I gave it some more tries :
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.
@leeyo
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).
@leeyo have you tested in other Android 5.0 device? Could be something related to that specific version.
Hi @FishDev,
I tried two more builds :
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 ! ;-)