public LinearLayoutManager(int orientation) { mOrientation = orientation; mOrientationHelper = OrientationHelper.CreateOrientationHelper(this, mOrientation); mLayoutState = new LayoutState(); mLayoutState.Offset = mOrientationHelper.GetStartAfterPadding(); }
public void ResetLayout(int direction, bool canUseExistingSpace, float space, OrientationHelper orientationHelper, LinearLayoutManager linearLayoutManager) { this.Extra = 0; this.LayoutDirection = direction; float scrollingOffset = 0.0f; if (direction == LayoutState.LAYOUT_END) { this.Extra += orientationHelper.GetEndPadding(); FlexibleViewViewHolder endChild = linearLayoutManager.GetChildClosestToEnd(); if (endChild != null) { // the direction in which we are traversing children this.ItemDirection = linearLayoutManager.mShouldReverseLayout ? LayoutState.ITEM_DIRECTION_HEAD : LayoutState.ITEM_DIRECTION_TAIL; this.CurrentPosition = endChild.LayoutPosition + linearLayoutManager.mLayoutState.ItemDirection; this.Offset = orientationHelper.GetViewHolderEnd(endChild); scrollingOffset = orientationHelper.GetViewHolderEnd(endChild) - orientationHelper.GetEndAfterPadding(); } } else { this.Extra += orientationHelper.GetStartAfterPadding(); FlexibleViewViewHolder startChild = linearLayoutManager.GetChildClosestToStart(); if (startChild != null) { this.ItemDirection = linearLayoutManager.mShouldReverseLayout ? LayoutState.ITEM_DIRECTION_TAIL : LayoutState.ITEM_DIRECTION_HEAD; this.CurrentPosition = startChild.LayoutPosition + linearLayoutManager.mLayoutState.ItemDirection; this.Offset = orientationHelper.GetViewHolderStart(startChild); scrollingOffset = -orientationHelper.GetViewHolderStart(startChild) + orientationHelper.GetStartAfterPadding(); } } this.Available = space; if (canUseExistingSpace) { this.Available -= scrollingOffset; } this.ScrollingOffset = scrollingOffset; }
public override float ComputeScrollOffset() { FlexibleViewViewHolder startChild = FindFirstVisibleItemView(); FlexibleViewViewHolder endChild = FindLastVisibleItemView(); if (ChildCount == 0 || startChild == null || endChild == null) { return(0); } int minPosition = Math.Min(startChild.LayoutPosition, endChild.LayoutPosition); int maxPosition = Math.Max(startChild.LayoutPosition, endChild.LayoutPosition); int itemsBefore = mShouldReverseLayout ? Math.Max(0, ItemCount - maxPosition - 1) : Math.Max(0, minPosition); float laidOutArea = Math.Abs(mOrientationHelper.GetViewHolderEnd(endChild) - mOrientationHelper.GetViewHolderStart(startChild)); int itemRange = Math.Abs(startChild.LayoutPosition - endChild.LayoutPosition) + 1; float avgSizePerRow = laidOutArea / itemRange; return((float)Math.Round(itemsBefore * avgSizePerRow + (mOrientationHelper.GetStartAfterPadding() - mOrientationHelper.GetViewHolderStart(startChild)))); }