public bool OnInterceptTouchEvent(RecyclerView rv, MotionEvent e)
        {
            View childView = rv.FindChildViewUnder(e.GetX(), e.GetY());
            if (childView != null && this.gestureDetector.OnTouchEvent(e)) 
            {
                this.OnClick(rv, childView, rv.GetChildAdapterPosition(childView));
            }

            return false;
        }
Пример #2
0
 public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     outRect.Left   = mSpace;
     outRect.Right  = mSpace;
     outRect.Bottom = mSpace;
     // Add top margin only for the first item to avoid double space between items
     if (parent.GetChildAdapterPosition(view) == 0)
     {
         outRect.Top = mSpace;
     }
 }
            public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
            {
                base.GetItemOffsets(outRect, view, parent, state);

                int position = parent.GetChildAdapterPosition(view);

                if (position == 0)
                {
                    outRect.Top = headerView.heightHeader;
                }
            }
        /// <summary>
        /// Ons the click.
        /// </summary>
        /// <param name="view">View.</param>
        public void OnClick(AView view)
        {
            var position = _recyclerView.GetChildAdapterPosition(view);

            //TODO: It is desirable that the forms side has Selected property and reflects it.
            //      But do it at a later as iOS side doesn't have that process.
            DeselectRow();

            var cell = view.FindViewById <LinearLayout>(Resource.Id.ContentCellBody).GetChildAt(0) as CellBaseView;

            if (cell == null || !_proxy[position].Cell.IsEnabled)
            {
                //if FormsCell IsEnable is false, does nothing.
                return;
            }

            _settingsView.Model.RowSelected(_proxy[position].Cell);

            cell.RowSelected(this, position);
        }
        public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
        {
            int viewPosition = parent.GetChildAdapterPosition(view);
            int viewCount    = parent.GetAdapter().ItemCount;

            switch (parent.GetLayoutManager())
            {
            case ResponsiveGridLayoutManager responsiveGridLayout:
                int adaptedSpace = (int)((_space - _verticalMargin * 2) * 0.66);
                int top          = adaptedSpace / 2;
                int bottom       = adaptedSpace / 2;
                int spanCount    = responsiveGridLayout.SpanCount;

                bool isViewEdgeTop = viewPosition < spanCount;
                if (isViewEdgeTop)
                {
                    top = 0;
                }

                bool isViewEdgeBottom = viewPosition / spanCount == viewCount - 1 / spanCount;
                if (isViewEdgeBottom)
                {
                    bottom = 0;
                }

                outRect.Set(0, top, 0, bottom);
                return;

            case LinearLayoutManager linearLayout:
                int  right           = _space / 2;
                int  left            = _space / 2;
                bool isViewEdgeLeft  = viewPosition == 0;
                bool isViewEdgeRight = viewPosition == viewCount - 1;

                if (isViewEdgeLeft)
                {
                    left = 0;
                }

                if (isViewEdgeRight)
                {
                    right = 0;
                }

                outRect.Set(left, 0, right, 0);
                return;
            }

            base.GetItemOffsets(outRect, view, parent, state);

            // InternalLogger.Info(
            //    $"view n°{viewPosition + 1} => left: {left}, right: {right}");
        }
Пример #6
0
        private void mMainView_Click(object sender, EventArgs e)
        {
            //get the index of the menu clicked
            int position = mRecyclerView.GetChildAdapterPosition((View)sender);

            //show the menu items for that menu in a new page
            Intent intent = new Intent(mcontext, typeof(MenuDisplayActivity));

            intent.PutExtra("MenuType", mMenuType[position].Menu);
            intent.PutExtra("RestaurantID", mMenuType[position].RestaurantID);
            mcontext.StartActivity(intent);
        }
Пример #7
0
        private void mMainView_Click(object sender, EventArgs e)
        {
            //getting the index of the clicked photo and sending its info to PhotoActivity so it can be displayed full size
            int position = mRecyclerView.GetChildAdapterPosition((View)sender);

            Console.WriteLine(mPhotos[position].PhotoFilePath);
            Intent intent = new Intent(mcontext, typeof(PhotoActivity));

            intent.PutExtra("PhotoFilePath", mPhotos[position].PhotoFilePath);
            intent.PutExtra("PhotoID", mPhotos[position].IDPhotos);
            mcontext.StartActivity(intent);
        }
            public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
            {
                base.GetItemOffsets(outRect, view, parent, state);

                var layoutManager = (GridLayoutManager)parent.GetLayoutManager();
                int position      = parent.GetChildAdapterPosition(view);

                if (position < layoutManager.SpanCount)
                {
                    outRect.Top = headerView.heightHeader;
                }
            }
        public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
        {
            int position = parent.GetChildAdapterPosition(view);

            // For first item, no offset needed
            if (position == 0)
            {
                return;
            }

            outRect.Top = _dividerHeight;
        }
Пример #10
0
        private void MakeToast(object sender, EventArgs e)
        {
            int position = recycler.GetChildAdapterPosition((View)sender);

            Android.Support.V4.App.Fragment fragment = FragmentSearch.NewInstance();
            Bundle args = new Bundle();

            args.PutString("search", cuisines[position].category);
            fragment.Arguments = args;
            activity.SupportFragmentManager.BeginTransaction()
            .Replace(Resource.Id.frameMainContent, fragment)
            .Commit();
        }
Пример #11
0
 public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     if (!_endSpace || (_endSpace && parent.GetChildAdapterPosition(view) != parent.GetAdapter().ItemCount - 1))
     {
         if (_orientation == Orientation.Vertical)
         {
             outRect.Bottom = _size;
         }
         else
         {
             outRect.Right = _size;
         }
     }
 }
        public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
        {
            var position = parent.GetChildAdapterPosition(view);

            if (position == IndexOffset && ShouldShowBeforeFirst)
            {
                outRect.Top = _drawableHeight;
            }

            if (position >= IndexOffset)
            {
                outRect.Bottom = _drawableHeight;
            }
        }
Пример #13
0
        public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
        {
            int itemPos = parent.GetChildAdapterPosition(view);

            TaskAdapter adapter = (TaskAdapter)parent.GetAdapter();

            if (!adapter.IsPositionAChildView(itemPos))
            {
                return;
            }

            outRect.Right = margin;
            outRect.Left  = margin;
        }
Пример #14
0
        public bool OnInterceptTouchEvent(RecyclerView rv, MotionEvent e)
        {
            var child = rv.FindChildViewUnder(e.GetX(), e.GetY());

            if (child != null && _clicklistener != null && _gestureDetector.OnTouchEvent(e))
            {
                _clicklistener.OnClick(child, rv.GetChildAdapterPosition(child));

                // https://medium.com/@anupdey99/multiple-click-problem-need-to-return-true-4a21b72f0953
                return(true);
            }

            return(false);
        }
Пример #15
0
        int GetSpanGroupIndex(AView view, RecyclerView parent)
        {
            var position = parent.GetChildAdapterPosition(view);

            if (_spanCount > 1)
            {
                if (parent.GetLayoutManager() is GridLayoutManager gridLayoutManager)
                {
                    return(gridLayoutManager.GetSpanSizeLookup().GetSpanGroupIndex(position, _spanCount));
                }
            }

            return(position);
        }
        public override void OnDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state)
        {
            base.OnDrawOver(canvas, parent, state);
            var topChild = parent.GetChildAt(0);

            if (topChild == null)
            {
                return;
            }

            int topChildPosition = parent.GetChildAdapterPosition(topChild);

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

            View currentHeader = GetHeaderViewForItem(topChildPosition, parent);

            if (currentHeader == null)
            {
                return;
            }

            FixLayoutSize(parent, currentHeader);

            int  contactPoint   = currentHeader.Bottom;
            View childInContact = GetChildInContact(parent, contactPoint, topChildPosition);

            if (childInContact != null && IStickyHeaderRecyclerView.IsHeader(parent.GetChildAdapterPosition(childInContact)))
            {
                MoveHeader(canvas, currentHeader, childInContact);
                return;
            }

            DrawHeader(canvas, currentHeader);
        }
Пример #17
0
            public override void OnDraw(Canvas cValue, RecyclerView parent, RecyclerView.State state)
            {
                base.OnDraw(cValue, parent, state);

                _layout.Layout(parent.Left, 0, parent.Right, _layout.MeasuredHeight);

                for (int i = 0; i < parent.ChildCount; i++)
                {
                    var view = parent.GetChildAt(i);

                    if (parent.GetChildAdapterPosition(view) == parent.ChildCount - 1)
                    {
                    }
                }
            }
        public void lista_Click(object sender, EventArgs e)
        {
            int    position = mRecyclerView.GetChildAdapterPosition((View)sender);
            string edad     = lstPersona[position].edad.ToString();
            int    id       = lstPersona[position].Id;

            try
            {
                irAcciones(cont, id, lstPersona[position].nombre, edad, lstPersona[position].ocupacion, lstPersona[position].sexo);
            }
            catch (Exception ex)
            {
                Log.Info("Error", ex.Message);
            }
        }
Пример #19
0
        private void Mainview_Click(object sender, EventArgs e)
        {
            int position = mrecycle.GetChildAdapterPosition((View)sender);
            Save_Task_Ref_Fragment nextFrag = new Save_Task_Ref_Fragment();
            FragmentTransaction    ft       = fragment.BeginTransaction();

            ft.Replace(Resource.Id.container, nextFrag);
            ft.AddToBackStack(null);
            ft.Commit();
            Bundle bundle = new Bundle();

            bundle.PutInt("pos", position);
            bundle.PutString("taskid", Mitems[position].task_id);
            nextFrag.Arguments = bundle;

            //string id = Mitems[position].task_id;
            //string task_descrip = Mitems[position].description;
            //DateTime deadline = Mitems[position].deadlineDate;
            //string task_name = Mitems[position].task_name;
            //string mark_by = Mitems[position].task_mark_by;
            //string creation_date = Mitems[position].task_creation_date;
            //string created_by = Mitems[position].task_created_by;
            //DateTime current = DateTime.Now;

            //TimeSpan span = deadline - current;
            //String.Format("{0} days, {1} hours, {2} minutes, {3} seconds",
            //span.Days, span.Hours, span.Minutes, span.Seconds);
            ////timeleft.Text = span.ToString();
            //ISharedPreferencesEditor editor = prefs.Edit();
            //editor.PutInt("position", position);
            //editor.Apply();

            //ComplainceFrag nextFrag = new ComplainceFrag();
            //fragment.BeginTransaction().Replace(Resource.Id.container, nextFrag).Commit();
            //Bundle bundle = new Bundle();
            //bundle.PutString("task_id", id);
            //nextFrag.Arguments = bundle;

            //Intent intent = new Intent(context, typeof( Activity_Compliance));
            //intent.PutExtra("task_id", id);
            ////intent.PutExtra("task_descrip", task_descrip);
            ////intent.PutExtra("deadline", deadline);
            ////intent.PutExtra("task_name", task_name);
            ////intent.PutExtra("mark_by", mark_by);
            ////intent.PutExtra("creation_date", creation_date);
            ////intent.PutExtra("created_by", created_by);
            //context.StartActivity(intent);
        }
Пример #20
0
        public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
        {
            var position = parent.GetChildAdapterPosition(view);
            var orientation = 0;
            int headerCount = 0, footerCount = 0;
            var adapterObj  = parent.GetAdapter();
            var adapterType = adapterObj.GetType();

            if (adapterType.IsAssignableFrom(typeof(RecyclerArrayAdapter <>)))
            {
                // ReSharper disable once PossibleNullReferenceException
                headerCount = (int)adapterType.GetMethod("GetHeaderCount")?.Invoke(adapterObj, null);
                // ReSharper disable once PossibleNullReferenceException
                footerCount = (int)adapterType.GetMethod("GetFooterCount")?.Invoke(adapterObj, null);
            }

            var layoutManager = parent.GetLayoutManager();

            switch (layoutManager)
            {
            case StaggeredGridLayoutManager manager:
                orientation = manager.Orientation;
                break;

            case GridLayoutManager gridLayoutManager:
                orientation = gridLayoutManager.Orientation;
                break;

            case LinearLayoutManager linearLayoutManager:
                orientation = linearLayoutManager.Orientation;
                break;
            }

            if ((position < headerCount || position >= parent.GetAdapter().ItemCount - footerCount) &&
                !_drawHeaderFooter)
            {
                return;
            }

            if (orientation == OrientationHelper.Vertical)
            {
                outRect.Bottom = _height;
            }
            else
            {
                outRect.Right = _height;
            }
        }
Пример #21
0
        private float ComputeRatio(RecyclerView recyclerView)
        {
            View child0 = recyclerView.GetChildAt(0);

            int pos = recyclerView.GetChildAdapterPosition(child0);

            if (pos != 0)
            {
                return(0);
            }

            int   height = child0.Height;
            float y      = Math.Max(0, child0.GetY());

            return(y / height);
        }
Пример #22
0
        public override void OnDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            var childCount = parent.ChildCount;

            if (childCount == 0)
            {
                return;
            }

            for (int i = 0; i + 1 < childCount; i++)
            {
                var child      = parent.GetChildAt(i);
                var viewHolder = parent.GetChildViewHolder(child);

                Type     type       = viewHolder.GetType();
                object[] attributes = type.GetCustomAttributes(typeof(ShadowAttribute), false);

                if (attributes.Length != 1)
                {
                    continue;
                }

                ShadowAttribute shadowAttr = attributes [0] as ShadowAttribute;

                if (ShouldDraw(child) && shadowAttr != null)
                {
                    var m     = shadowAttr.Modes;
                    var left  = parent.PaddingLeft;
                    var right = child.Right + child.PaddingRight;

                    if (m.HasFlag(top) && topShadowHeightInPixels > 0 && parent.GetChildAdapterPosition(child) != 0)
                    {
                        var shadowBottom = child.Top + topShadowHeightInPixels;
                        shadow.SetBounds(left, child.Top, right, shadowBottom);
                        shadow.Draw(c);
                    }

                    if (m.HasFlag(bottom) && bottomShadowHeightInPixels > 0)
                    {
                        var reverseShadowTop = child.Bottom - bottomShadowHeightInPixels;
                        reverseShadow.SetBounds(left, reverseShadowTop, right, child.Bottom);
                        reverseShadow.Draw(c);
                    }
                }
            }
        }
Пример #23
0
        /**
         * Get position of center child in Y Axes
         */
        public static int GetCenterYChildPosition(RecyclerView recyclerView)
        {
            int childCount = recyclerView.ChildCount;

            if (childCount > 0)
            {
                for (int i = 0; i < childCount; i++)
                {
                    View child = recyclerView.GetChildAt(i);
                    if (IsChildInCenterY(recyclerView, child))
                    {
                        return(recyclerView.GetChildAdapterPosition(child));
                    }
                }
            }
            return(childCount);
        }
            public override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
            {
                base.OnScrolled(recyclerView, dx, dy);

                if (scrolledY == int.MinValue)
                {
                    var child             = recyclerView.GetChildAt(0);
                    var positionFirstItem = recyclerView.GetChildAdapterPosition(child);
                    var heightDecorator   = positionFirstItem == 0 ? 0 : headerView.heightHeader;
                    var offset            = recyclerView.ComputeVerticalScrollOffset();
                    scrolledY = offset + heightDecorator;
                }
                else
                {
                    scrolledY += dy;
                }

                headerView.headerAnimator.OnScroll(-scrolledY);
            }
Пример #25
0
        public static int CalculateCenterItemIndex(this RecyclerView recyclerView, int firstVisibleItemIndex, LinearLayoutManager linearLayoutManager, bool lookCenteredOnXAndY)
        {
            // This can happen if a layout pass has not happened yet
            if (firstVisibleItemIndex == -1)
            {
                return(firstVisibleItemIndex);
            }

            AView centerView;

            if (linearLayoutManager.Orientation == LinearLayoutManager.Horizontal)
            {
                float centerX = recyclerView.Width / 2;
                float centerY = recyclerView.Top;

                if (lookCenteredOnXAndY)
                {
                    centerY = recyclerView.Height / 2;
                }

                centerView = recyclerView.FindChildViewUnder(centerX, centerY);
            }
            else
            {
                float centerY = recyclerView.Height / 2;
                float centerX = recyclerView.Left;

                if (lookCenteredOnXAndY)
                {
                    centerX = recyclerView.Width / 2;
                }

                centerView = recyclerView.FindChildViewUnder(centerX, centerY);
            }

            if (centerView != null)
            {
                return(recyclerView.GetChildAdapterPosition(centerView));
            }

            return(firstVisibleItemIndex);
        }
        public override void GetItemOffsets(Rect outRect, AView view, RecyclerView parent, RecyclerView.State state)
        {
            base.GetItemOffsets(outRect, view, parent, state);

            if (Math.Abs(_adjustedVerticalSpacing - (-1)) < double.Epsilon)
            {
                _adjustedVerticalSpacing = parent.Context.ToPixels(_verticalSpacing);
            }

            if (Math.Abs(_adjustedHorizontalSpacing - (-1)) < double.Epsilon)
            {
                _adjustedHorizontalSpacing = parent.Context.ToPixels(_horizontalSpacing);
            }

            int position  = parent.GetChildAdapterPosition(view);
            int itemCount = parent.GetAdapter().ItemCount;

            if (position == RecyclerView.NoPosition || itemCount == 0)
            {
                return;
            }

            if (_orientation == ItemsLayoutOrientation.Vertical)
            {
                var verticalInsets       = parent.Context.ToPixels(_carouselView.PeekAreaInsets.Bottom + _carouselView.PeekAreaInsets.Top) / 2;
                var finalVerticalSpacing = (int)(_adjustedVerticalSpacing - (_verticalSpacing * 2));

                outRect.Left   = position == 0 ? 0 : (int)_adjustedHorizontalSpacing;
                outRect.Bottom = (position == (itemCount - 1) && verticalInsets > 0) ? ((int)Math.Ceiling(verticalInsets / 2) + finalVerticalSpacing) : finalVerticalSpacing;
                outRect.Top    = (position == 0 && verticalInsets > 0) ? ((int)Math.Ceiling(verticalInsets / 2) + finalVerticalSpacing) : finalVerticalSpacing;
            }

            if (_orientation == ItemsLayoutOrientation.Horizontal)
            {
                var horizontalInsets       = parent.Context.ToPixels(_carouselView.PeekAreaInsets.Left + _carouselView.PeekAreaInsets.Right) / 2;
                var finalHorizontalSpacing = (int)(_adjustedHorizontalSpacing - (_horizontalSpacing * 2));

                outRect.Top   = position == 0 ? 0 : (int)_adjustedVerticalSpacing;
                outRect.Right = (position == (itemCount - 1) && horizontalInsets > 0) ? ((int)Math.Ceiling(horizontalInsets / 2) + finalHorizontalSpacing) : finalHorizontalSpacing;
                outRect.Left  = (position == 0 && horizontalInsets > 0) ? ((int)Math.Ceiling(horizontalInsets / 2) + finalHorizontalSpacing) : finalHorizontalSpacing;
            }
        }
Пример #27
0
        public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
        {
            base.GetItemOffsets(outRect, view, parent, state);

            int position = parent.GetChildAdapterPosition(view);

            bool hasHeader = !_viewModel.TopBanners.IsNullOrEmpty();
            bool isHeader  = position == 0 && hasHeader;

            bool hasFooter = !_viewModel.BottomBanners.IsNullOrEmpty();
            bool isFooter  = (position == (_viewModel.Items.Count + (hasHeader ? 1 : 0)) && hasFooter);

            if (isHeader || isFooter)
            {
                outRect.Set(0, 0, 0, 0);
            }
            else
            {
                if (parent.GetLayoutManager() is GridLayoutManager layoutManager)
                {
                    //having header so adjust indexing for "smart" spacing
                    if (hasHeader)
                    {
                        position--;
                    }

                    int spanCount = layoutManager.SpanCount;
                    int column    = position % spanCount;

                    int left   = (int)(_spacing - (float)column * _spacing / spanCount),
                        right  = (int)((column + 1) * (float)_spacing / spanCount),
                        top    = position < spanCount ? _spacing : 0,
                        bottom = _spacing;

                    outRect.Set(left, top, right, bottom);
                }
                else
                {
                    outRect.Set(_spacing, _spacing, _spacing, _spacing);
                }
            }
        }
            public override void GetItemOffsets(Rect outRect, Android.Views.View view, RecyclerView parent, RecyclerView.State state)
            {
                var holder       = parent.GetChildViewHolder(view) as ContentViewHolder;
                var position     = parent.GetChildAdapterPosition(view);
                var realPosition = position;

                if (_renderer._hCollectionView.IsInfinite)
                {
                    realPosition = _renderer.Adapter.GetRealPosition(position);
                }

                if (holder.IsHeader)
                {
                    outRect.Right = _renderer._firstSpacing;
                    if (position != 0)
                    {
                        outRect.Left = _renderer._lastSpacing;
                    }

                    return;
                }

                // Disabled grouping first spacing is applied at the first cell.
                if (!_renderer._hCollectionView.IsGroupingEnabled && position == 0)
                {
                    outRect.Left = _renderer._firstSpacing;
                }

                // Group last or single last spacing is applied at the last cell.
                if (position == _renderer.Adapter.ItemCount - 1)
                {
                    outRect.Right = _renderer._lastSpacing;
                }

                if (position == 0 || _renderer.Adapter.FirstSectionItems.Contains(realPosition))
                {
                    return;
                }

                outRect.Left = _renderer._spacing;
            }
Пример #29
0
        public override void OnDraw (Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            var childCount = parent.ChildCount;

            if (childCount == 0) {
                return;
            }

            for (int i = 0; i+1 < childCount; i++) {
                var child = parent.GetChildAt (i);
                var viewHolder = parent.GetChildViewHolder (child);

                Type type = viewHolder.GetType ();
                object[] attributes = type.GetCustomAttributes (typeof (ShadowAttribute), false);

                if (attributes.Length != 1) {
                    continue;
                }

                ShadowAttribute shadowAttr = attributes [0] as ShadowAttribute;

                if (ShouldDraw (child) && shadowAttr != null) {

                    var m = shadowAttr.Modes;
                    var left = parent.PaddingLeft;
                    var right = child.Right + child.PaddingRight;

                    if (m.HasFlag (top) && topShadowHeightInPixels > 0 && parent.GetChildAdapterPosition (child) != 0) {
                        var shadowBottom = child.Top + topShadowHeightInPixels;
                        shadow.SetBounds (left, child.Top, right, shadowBottom);
                        shadow.Draw (c);
                    }

                    if (m.HasFlag (bottom) && bottomShadowHeightInPixels > 0) {
                        var reverseShadowTop = child.Bottom - bottomShadowHeightInPixels;
                        reverseShadow.SetBounds (left, reverseShadowTop, right, child.Bottom);
                        reverseShadow.Draw (c);
                    }
                }
            }
        }
        public override void GetItemOffsets(Rect outRect, Android.Views.View view, RecyclerView parent, RecyclerView.State state)
        {
            if (initializationWidth != parent.Width)
            {
                if (parent.MeasuredWidth <= 0)
                {
                    return;
                }
                Init(parent.MeasuredWidth);
            }
            var position     = parent.GetChildAdapterPosition(view);
            var colSize      = adapter.colSize;
            var row          = position / colSize;
            var col          = position % colSize;
            var horizPadding = rightArrow.Width / 2;
            var vertPadding  = rightArrow.Height;

            int l = horizPadding, t = 0, r = horizPadding, b = vertPadding;

            outRect.Set(l, t, r, b);
        }
Пример #31
0
        public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
        {
            int position = parent.GetChildAdapterPosition(view);
            int orientation = 0;
            int headerCount = 0, footerCount = 0;
            var adapterObj  = parent.GetAdapter();
            var adapterType = adapterObj.GetType();

            if (adapterType.IsAssignableFrom(typeof(RecyclerArrayAdapter <>)))
            {
                headerCount = (int)adapterType.GetMethod("GetHeaderCount").Invoke(adapterObj, null);
                footerCount = (int)adapterType.GetMethod("GetFooterCount").Invoke(adapterObj, null);
            }

            RecyclerView.LayoutManager layoutManager = parent.GetLayoutManager();
            if (layoutManager is StaggeredGridLayoutManager)
            {
                orientation = ((StaggeredGridLayoutManager)layoutManager).Orientation;
            }
            else if (layoutManager is GridLayoutManager)
            {
                orientation = ((GridLayoutManager)layoutManager).Orientation;
            }
            else if (layoutManager is LinearLayoutManager)
            {
                orientation = ((LinearLayoutManager)layoutManager).Orientation;
            }

            if (position >= headerCount && position < parent.GetAdapter().ItemCount - footerCount || mDrawHeaderFooter)
            {
                if (orientation == OrientationHelper.Vertical)
                {
                    outRect.Bottom = mHeight;
                }
                else
                {
                    outRect.Right = mHeight;
                }
            }
        }
Пример #32
0
        public override void GetItemOffsets(Rect outRect, AView view, RecyclerView parent, RecyclerView.State state)
        {
            base.GetItemOffsets(outRect, view, parent, state);

            var position = parent.GetChildAdapterPosition(view);

            if (position == 0)
            {
                return;
            }

            if (_adjustedVerticalSpacing == -1)
            {
                _adjustedVerticalSpacing = parent.Context.ToPixels(_verticalSpacing);
            }

            if (_adjustedHorizontalSpacing == -1)
            {
                _adjustedHorizontalSpacing = parent.Context.ToPixels(_horizontalSpacing);
            }

            var firstInRow = false;
            var firstInCol = false;

            if (_orientation == ItemsLayoutOrientation.Vertical)
            {
                firstInRow = position >= _span && position % _span == 0;
                firstInCol = position < _span;
            }

            if (_orientation == ItemsLayoutOrientation.Horizontal)
            {
                firstInCol = position >= _span && position % _span == 0;
                firstInRow = position < _span;
            }

            outRect.Top  = firstInCol ? 0 : (int)_adjustedVerticalSpacing;
            outRect.Left = firstInRow ? 0 : (int)_adjustedHorizontalSpacing;
        }
			public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
			{
				base.GetItemOffsets(outRect, view, parent, state);

				var layoutManager = (StaggeredGridLayoutManager)parent.GetLayoutManager();
				int position = parent.GetChildAdapterPosition(view);
				if (position < layoutManager.SpanCount)
				{
					outRect.Top = headerView.heightHeader;
				}
			}
			public override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
			{
				base.OnScrolled(recyclerView, dx, dy);
				
				if (scrolledY == int.MinValue)
				{
					var child = recyclerView.GetChildAt(0);
					var positionFirstItem = recyclerView.GetChildAdapterPosition(child);
					var heightDecorator = positionFirstItem == 0 ? 0 : headerView.heightHeader;
					var offset = recyclerView.ComputeVerticalScrollOffset();
					scrolledY = offset + heightDecorator;
				}
				else
				{
					scrolledY += dy;
				}

				headerView.headerAnimator.OnScroll(-scrolledY);
			}
			public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
			{
				base.GetItemOffsets(outRect, view, parent, state);

				int position = parent.GetChildAdapterPosition(view);
				if (position == 0)
				{
					outRect.Top = headerView.heightHeader;
				}
			}
 public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     if (parent.GetChildAdapterPosition(view) % 2 == 1) outRect.Left = mHorizontalSpaceHeight;
     outRect.Bottom = mVerticalSpaceHeight;
 }