view.Elevation = elevation.Value;
}
+
+ internal static float? GetElevation(global::Android.Views.View view)
+ {
+ if (view == null || !Forms.IsLollipopOrNewer)
+ {
+ return null;
+ }
+
+ return view.Elevation;
+ }
+
+ internal static float? GetElevation(VisualElement element)
+ {
+ if (element == null || !Forms.IsLollipopOrNewer)
+ {
+ return null;
+ }
+
+ var iec = element as IElementConfiguration<VisualElement>;
+ var elevation = iec?.On<PlatformConfiguration.Android>().GetElevation();
+
+ return elevation;
+ }
}
}
\ No newline at end of file
using Xamarin.Forms.Internals;
using Android.Views;
using AView = Android.Views.View;
-using System.Linq;
namespace Xamarin.Forms.Platform.Android
{
}
void EnsureChildOrder()
{
+ float elevationToSet = 0;
for (var i = 0; i < ElementController.LogicalChildren.Count; i++)
{
Element child = ElementController.LogicalChildren[i];
{
IVisualElementRenderer r = Platform.GetRenderer(element);
if (r != null)
+ {
+ if (Forms.IsLollipopOrNewer)
+ {
+ var elevation = ElevationHelper.GetElevation(r.View) ?? 0;
+ var elementElevation = ElevationHelper.GetElevation(element);
+
+ if (elementElevation == null)
+ {
+ if (elevation > elevationToSet)
+ elevationToSet = elevation;
+
+ r.View.Elevation = elevationToSet;
+ }
+ }
+
(_renderer.View as ViewGroup)?.BringChildToFront(r.View);
+ }
}
}
}
if (view != null)
AddChild(view);
- if (ElementController.LogicalChildren.LastOrDefault() != view)
+ int itemCount = ElementController.LogicalChildren.Count;
+ if (itemCount <= 1)
+ return;
+
+
+ Element lastChild = ElementController.LogicalChildren[itemCount - 1];
+
+ if(lastChild != view)
+ {
+ EnsureChildOrder();
+ return;
+ }
+
+ if (!Forms.IsLollipopOrNewer)
+ return;
+
+ Element previousChild = ElementController.LogicalChildren[itemCount - 2];
+
+ IVisualElementRenderer lastRenderer = null;
+ IVisualElementRenderer previousRenderer = null;
+
+ if (lastChild is VisualElement last)
+ lastRenderer = Platform.GetRenderer(last);
+
+ if (previousChild is VisualElement previous)
+ previousRenderer = Platform.GetRenderer(previous);
+
+ if (ElevationHelper.GetElevation(lastRenderer?.View) < ElevationHelper.GetElevation(previousRenderer?.View))
EnsureChildOrder();
}