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));
        }
Exemple #2
0
        public override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
        {
            base.OnScrolled(recyclerView, dx, dy);
            LinearLayoutManager manager = (LinearLayoutManager)recyclerView.GetLayoutManager();
            //获取最后一个完全显示的itemPosition
            int lastItemPosition = manager.FindLastCompletelyVisibleItemPosition();
            int itemCount        = manager.ItemCount;

            // 判断是否滑动到了最后一个item
            if (lastItemPosition == (itemCount - 3))
            {
                //加载更多
                onLoadMore();
            }
        }
Exemple #3
0
        public override void OnScrolled(Android.Support.V7.Widget.RecyclerView recyclerView, int dx, int dy)
        {
            LinearLayoutManager layoutManager = (LinearLayoutManager)recyclerView.GetLayoutManager();

            int firstVisible = layoutManager.FindFirstVisibleItemPosition();
            int visibleCount = Math.Abs(firstVisible - layoutManager.FindLastCompletelyVisibleItemPosition());
            int itemCount    = recyclerView.GetAdapter().ItemCount;

            if (firstVisible != _lastFirstVisible || visibleCount != _lastVisibleCount || itemCount != _lastItemCount)
            {
                _scrollListener.OnScroll(null, firstVisible, visibleCount, itemCount);
                _lastVisibleCount = firstVisible;
                _lastVisibleCount = visibleCount;
                _lastItemCount    = itemCount;
            }
        }
            public override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
            {
                base.OnScrolled(recyclerView, dx, dy);
                if (viewModel.IsBusy || viewModel.Trips.Count == 0 || !viewModel.CanLoadMore)
                {
                    return;
                }

                var lastVisiblePosition = layoutManager.FindLastCompletelyVisibleItemPosition();

                if (lastVisiblePosition == RecyclerView.NoPosition)
                {
                    return;
                }

                //if we are at the bottom and can load more.
                if (lastVisiblePosition == viewModel.Trips.Count - 1)
                {
                    viewModel.LoadMorePastTripCommand.Execute(null);
                }
            }
 private int GetLastCompletelyVisibleItemPosition()
 {
     return(mLayoutManager.FindLastCompletelyVisibleItemPosition());
 }