protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            base.OnLayout(changed, left, top, right, bottom);

            if (!changed)
            {
                return;
            }

            var startPos = _layoutManager.FindFirstCompletelyVisibleItemPosition();
            var endPos   = _layoutManager.FindLastCompletelyVisibleItemPosition();

            int totalH = 0;

            for (var i = startPos; i <= endPos; i++)
            {
                var child = _layoutManager.GetChildAt(i);

                if (child == null)
                {
                    return;
                }

                totalH += _layoutManager.GetChildAt(i).Height;
            }
            Element.VisibleContentHeight = Context.FromPixels(Math.Min(totalH, Control.Height));
        }
        /// <summary>
        /// This method calculates the current scroll position and its offset to help new attached
        /// recyclerView on window at that position and offset
        /// </summary>
        /// <seealso cref="GetScrollPosition()"/>
        /// <seealso cref="GetScrollPositionOffset()"/>
        private void RenewScrollPosition(RecyclerView recyclerView)
        {
            LinearLayoutManager layoutManager = (LinearLayoutManager)recyclerView.GetLayoutManager();

            mScrollPosition = layoutManager.FindFirstCompletelyVisibleItemPosition();
            // That means there is no completely visible Position.
            if (mScrollPosition == -1)
            {
                mScrollPosition = layoutManager.FindFirstVisibleItemPosition();
                // That means there is just a visible item on the screen
                if (mScrollPosition == layoutManager.FindLastVisibleItemPosition())
                {
                }
                else
                {
                    // in this case we use the position which is the last & first visible item.
                    // That means there are 2 visible item on the screen. However, second one is not
                    // completely visible.
                    mScrollPosition = mScrollPosition + 1;
                }
            }

            mScrollPositionOffset = layoutManager.FindViewByPosition(mScrollPosition).Left;
        }
 private int GetFirstCompletelyVisibleItemPosition()
 {
     return(mLayoutManager.FindFirstCompletelyVisibleItemPosition());
 }