xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Android] Can't Overlap a Button with any view #3543

Closed Phenek closed 5 years ago

Phenek commented 6 years ago

Description

It's for now impossible to overlap a button on Android with another view.

Steps to Reproduce

  1. Add a button on a layout (AbsoluteLayout, Grid,.. "kind of layout that allows overlap")
  2. Then add another view (ActivityIndicator, Image, Notification Badges, text, ..) on the layout
  3. The Button always in front

Expected Behavior

The expected hierarchy of the visual stack would be:

Actual Behavior

The button is stuck on the front of the visual stack.

Basic Information

samhouts commented 6 years ago

Issue3543.zip

I am not seeing the behavior described. Please test the attached project and alter it such that it exhibits the problem. Thank you!

Phenek commented 6 years ago

First thanks for your time,

I figured out, the only things that create this bug. It's because I was using this flag in my MainActivity.cs: Forms.SetFlags("FastRenderers_Experimental");

Obviously the Button FastRenderer is rendering on top of the visual stack. Seems this issue can be close or can be move to an experimental section.

Regards,

PS: Another thing with FastRenderers If you create a layout (AbsoluteLayout, Grid,.. "kind of layout that allows overlap") with a Xaml button in Xaml, then add another button programmatically to overlap the Xaml button. At this moment the Xaml button is on front overlapping everything, so Xaml have the priority to be on front, or it's rendering at the end?

samhouts commented 6 years ago

Yep, you are correct! The FastRenderer Button sticks on top.

Priority should be given to whatever element is added to the layout last, regardless of XAML or programmatic. Your experience seems to be another artifact of FastRenderers not being layered properly.

Thanks!

ult-ghasan commented 5 years ago

Exactly similar to what I am facing with a catch. I am using a couple of frames and a label, the frames within each other seems fine in stacking, but when another type is introduced (Label), it goes behind even though it is should be at the forefront. This is only happening on Android (left), while in iOS (right), it is working.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App3"
             x:Class="App3.MainPage">

    <AbsoluteLayout>
        <Frame BackgroundColor="Green" AbsoluteLayout.LayoutBounds="0,0,200,30" HeightRequest="30" Padding="0"/>
        <Frame BackgroundColor="Brown" AbsoluteLayout.LayoutBounds="0,0,150,30" HeightRequest="30" Padding="0"/>
        <Label BackgroundColor="Purple" AbsoluteLayout.LayoutBounds="0,0,100,30" HeightRequest="30" Text="Hi" TextColor="White"/>
    </AbsoluteLayout>

</ContentPage>

overlap error

PS: RaiseChild() and LowerChild() does not work too.

WarBorg commented 4 years ago

@samhouts this is still an issue with fast renderers if you place the button on a layout (AbsoluteLayout, Grid,.. "kind of layout that allows overlap") and all of that into a ScrollView and into a NavigationPage it will duplicate the same behaviour as mentioned in the original bug

there is also a related issue with this, having the button on a layout (AbsoluteLayout, Grid,.. "kind of layout that allows overlap") with something in front of it, it I click the button it will come in front of the other visual elements

Test app

please see the test app I made for this scenarios https://github.com/WarBorg/TestActivityButtonXamForms

Basic Information

using latest Xamarin Framework 4.5.0.396 using Android 9.0 - api 28 emulator

Known workaround:

switch to "UseLegacyRenderers"

PS please tell me if I need to create a new issue and I will do that, thank you

samhouts commented 4 years ago

@WarBorg Yes, please create a new issue! Thank you!!!