aescript
aescript

Reputation: 1925

Xamarin Forms - Image element disappearing under button element onclick in absolute layout

I have an absolutelayout which has a Button and an Image laid into the same space, with the image coming second to be on top. Its just to position the image where i like on the button rather than where it goes using ImageSource attribute.

This works fine when the page is shown originally, but once you press one of those buttons, the image that was overtop disappears. Its almost like it falls behind in Z order or something - however in the OnClick method I tried doing

AbsoluteLayout.RaiseChild(image);

as well as

AbsoluteLayout.Children.Remove(image);
AbsoluteLayout.Children.Insert(0, image);

but neither seems to bring it back to visibility.

Is this just an oversight somewhere on my part, or is there a trick to keeping the image on top (or visible, if its not a depth issue)enter image description here

Upvotes: 0

Views: 378

Answers (1)

Junior Jiang
Junior Jiang

Reputation: 12723

This problem is caused by Fast Renderers in Xamarin Forms.

You could enable the legacy renderers by adding the following line of code to your MainActivity class before calling Forms.Init:

Forms.SetFlags("UseLegacyRenderers");

Here is my Xaml code:

<AbsoluteLayout x:Name="myAbsoluteLayout">
    <Button Text="Button"
            BackgroundColor="LightBlue"
            Clicked="Button_Clicked"
            x:Name="button"
            AbsoluteLayout.LayoutBounds="0.5,0,100,50"
            AbsoluteLayout.LayoutFlags="PositionProportional" />
    <Image x:Name="firstImage"
            Source="icon.png"
            InputTransparent="False"
            AbsoluteLayout.LayoutBounds="0.5,0,25,25"
            AbsoluteLayout.LayoutFlags="PositionProportional" />
</AbsoluteLayout>

The effect:

enter image description here

Upvotes: 1

Related Questions