1

I am using a MacBook Pro that does not have hardward acceleration for graphics, so maybe that's the whole problem, but I hope not.

When I use VisualStudio to run a Xamarin.Forms app on the iPhone simulator, it works fine.

When I run it on the Android simulator (right now the Pixel, but it's the same for all of them), it works OK but none of the images show up.

How can I get the images to show up on Android?

Here's an example of code where it happens (you'll have to change the image path for it to work):

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="UdemyHelloWorldOne.AbsoluteLayoutExercise2">
    <AbsoluteLayout>
        <Image Source="/Users/jesseonbookofe/Documents/Xamarin/UdemyHelloWorldOne/UdemyHelloWorldOne/absolutelayoutexercise2-image-flower.jpg" 
            Aspect="AspectFill" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" 
            AbsoluteLayout.LayoutFlags="All" />
        <Label Text="Relax" FontSize="30" TextColor="White"
            AbsoluteLayout.LayoutFlags="SizeProportional, XProportional"
            AbsoluteLayout.LayoutBounds="0.5,20,1,0.1" 
            HorizontalOptions="Center"/>
        <BoxView BackgroundColor="Black" Opacity="0.5" 
            AbsoluteLayout.LayoutFlags="PositionProportional, WidthProportional"
            AbsoluteLayout.LayoutBounds="0,1,1,100"/>
        <StackLayout AbsoluteLayout.LayoutBounds="0,1,1,100" Padding="30,0"
            Orientation="Horizontal" VerticalOptions="Center"
            AbsoluteLayout.LayoutFlags="PositionProportional, WidthProportional">
            <Label Text="Profile" FontSize="15" TextColor="White"/>
            <Label Text="Meditate" FontSize="15" TextColor="White"
                HorizontalOptions="CenterAndExpand"/>
            <Label Text="Themes" FontSize="15" TextColor="White"/>
        </StackLayout>
    </AbsoluteLayout>
</ContentPage>
Le Mot Juiced
  • 3,761
  • 1
  • 26
  • 46
  • Thanks for the pointer, but the link gets me 404. I'll follow the lead though. – Le Mot Juiced Mar 08 '18 at 19:09
  • Also, you'll have trouble with an image filename with a dash in it on Android https://stackoverflow.com/questions/35755089/xamarin-forms-image-not-showing/35760195#35760195 – DavidS Mar 08 '18 at 19:30
  • correct url is https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/ – Jason Mar 08 '18 at 19:36
  • @Jason okay, I followed those instructions, but two problems: 1) now the image actually doesn't show on either platform, 2) the "Build Action: AndroidResource" option isn't available on the Build Actions menu. I'd tried some of this before and couldn't get it to work and that's why I had to use the ridiculous path name in the first place. – Le Mot Juiced Mar 10 '18 at 10:29
  • are you placing the images in the correct projects? They go in the platform projects (iOS, Android, etc) not the shared project – Jason Mar 10 '18 at 16:35
  • Okay I went down the rabbit hole on all this and indeed I wasn't putting images in the right places. What I ultimately wanted was to just put the image in one place in my project, and that requires a C# extension, detailed on the same page you linked. If you want to put up an answer I'll award it. – Le Mot Juiced Mar 12 '18 at 10:30

1 Answers1

0

Xamarin android and iOS does not support if image name contain hyphen.

  • 1
    Welcome to Stackoverflow! Please provide a specific answer supported with links. If you have a suggestion or need clarification leave a comment. We have guidelines on [How to write a good answer](https://stackoverflow.com/help/how-to-answer). – Joseph Cho Nov 06 '18 at 13:56