1

I am trying to implement nested scrolling by myself (due to environment limitations i cant use Coordinator and AppBarLayout). So i created a CoordinatorControl that derives from StackLayout and implements INestedScrollingParent which holds the bar view and content view and synchronizng the nested scroll between them.

This is part of CoordinatorControlRenderer : ViewRenderer<CoordinatorControl, LinearLayout>, INestedScrollingParent

   void INestedScrollingParent.OnNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
    {

        if (dyConsumed > 0)
        {
            scrollDown = false;
        }
        else
        {
            scrollDown = true;
        }
        if (dyConsumed != 0 && (!scrollDown && totalPixels < barViewNative.Height || scrollDown && totalPixels > 0))
        {
            totalPixels += dyConsumed;
            if (!scrollDown && totalPixels > barViewNative.Height)
            {
                totalPixels = (int)barViewNative.Height;
            }
            else if (scrollDown && totalPixels <0)
            {
                totalPixels = 0;
            }

            barViewNative.TranslationY = -totalPixels;
            contentViewNative.TranslationY = -totalPixels;
            }
        else
        {
            target.ScrollY += dyConsumed;
        }
    }

Nested scrolling works fine (the bar view is collapsing and expanding as it should). the only problem is that when collapsed i have a gap at the bottom of the screen which i am having trouble to fill.

Bar View Expanded:

Expanded

Bar View Collapsed:

Collapsed

I tried to change contentView Height and gravity with no avail. how can i change the contentView Height or ask it to fill remaining space automatically?

Ori Price
  • 3,593
  • 2
  • 22
  • 37

0 Answers0