0

I am trying to overlay two xamarin pages on top of each other, one as the main, the other as a preview that can be expanded if needed. Akin to a spotify mini player that stays on top of the NavigationPage contents.

I have a custom page renderer where I create the child page renderer, add it to the parent's subviews then layout but... the child page ignores the layout and is always fullscreen.

        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            var renderer=Platform.GetRenderer((Element as RootPage)?.Mini);
            if (renderer == null)
            {
                renderer= Platform.CreateRendererWithContext(MiniPage, Context);
                Platform.SetRenderer(MiniPage, renderer);
            }
            renderer.View.RemoveFromParent();
            _miniView=renderer.View;

            AddView(_miniView);
            _miniView.Layout(0,Height-400,Width,400);
        }

        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);
            _miniView?.Layout(0, Height-400,Width, Height);
        }

This of-course works fine on iOS...

The only reason why I am trying to embed a Page rather than a View is that the call to Platform.CreateRenderer always returns an unitialized view as it is not in the parent page's Visual Tree.

Florian Doyon
  • 4,146
  • 1
  • 27
  • 37
  • Is it because this line `_miniView?.Layout(0, Height-400,Width, Height);` sets the Height to `Height` ? – Leo Zhu Aug 19 '20 at 07:46
  • Thanks @LeoZhu-MSFT - this is the Android View layout method, the signature is `void Layout(int Left, int Top, int Right, int Bottom)` and defines the coordinates of the bounding box for the view according to the documentation here: https://developer.android.com/reference/android/view/ViewGroup#layout(int,%20int,%20int,%20int) - in this case I want to layout the child to the bottom part of the screen – Florian Doyon Aug 19 '20 at 14:23

0 Answers0