Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Button in a AbsoluteLayout issue

KevinAtKeshetKevinAtKeshet CAMember ✭✭
edited November 2019 in Xamarin.Forms

So I have an odd thing happening with last update and I am not sure what to do about it.

I have a view

  <ContentView.Content>
        <AbsoluteLayout WidthRequest="100" HeightRequest="100">
            <Button x:Name="BackgroundButton" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" />
            <Image x:Name="Icon" InputTransparent="True" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" Margin="20,15,20,25"/>
            <Label x:Name="CountLabel" Style="{StaticResource HubButtonLabel}" HorizontalTextAlignment="End" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"  />
            <Label x:Name="ButtonLabel" Style="{StaticResource HubButtonLabel}" HorizontalTextAlignment="Center" VerticalTextAlignment="End" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"  />
        </AbsoluteLayout>
  </ContentView.Content>
</ContentView>

Is basically just a button wrapper, with some extra icons, and text. I have a few of these in the project of different styles and layouts. Until the last update they worked fine. Now the button renders overtop of everything else. I can confirm that by setting the button colour to something semi transparent.

This only happens on android, ios still works as expected.
Anyone have a fix for that? or do I need to rework all these views?

Tagged:

Best Answer

Answers

  • KevinAtKeshetKevinAtKeshet CAMember ✭✭

    Update - So while this isn't really a fix, but also kind of is. If I swap out the Button for an ImageButton - they work again as expected on both platforms. Bug perhaps with button on android?

  • LandLuLandLu Member, Xamarin Team Xamurai

    Do you mean you utilized the latest Forms version?
    I tested your code above on Android 9.0 emulators with Forms version 4.3.0.947036 it displayed the custom content view correctly.
    Can you share a sample to help me reproduce your issue?

  • KevinAtKeshetKevinAtKeshet CAMember ✭✭

    @LandLu said:
    Do you mean you utilized the latest Forms version?
    I tested your code above on Android 9.0 emulators with Forms version 4.3.0.947036 it displayed the custom content view correctly.
    Can you share a sample to help me reproduce your issue?

    Yes, same forms version you listed. It happens on both android 9 and 10 emulators.

    I can't post the projects and have several with the same issue. I made a test project that just has a page with the buttons. Updated all nuget packages to current versions.

    In this project, Initially the image appears proper, however as soon as you click the button, it reverts to the broken state. If I switch to an ImageButton, it acts properly. In your test does it break when you click the button? I have attached my test project.

  • KevinAtKeshetKevinAtKeshet CAMember ✭✭

    @JGoldberger said:
    Thanks for the test project and report.

    This is actually a known issue: https://github.com/xamarin/Xamarin.Forms/issues/7300

    It is an issue with the new FastRenderers for Android which became the default in Xam.Forms 4.0. If you want to workaround this issue, you can disable the FastRenderers. See: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/internals/fast-renderers#backwards-compatibility

    Just add the following to your MainActivity.OnCreate before the global::Xamarin.Forms.Forms.Init(this, savedInstanceState) call:

    global::Xamarin.Forms.Forms.SetFlags("UseLegacyRenderers");
    

    Thanks, this worked perfect.

Sign In or Register to comment.