Java Code Examples for androidx.recyclerview.widget.RecyclerView#getChildLayoutPosition()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#getChildLayoutPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DividerGridItemDecorationUtils.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
        super.getItemOffsets(outRect, view, parent, state);
        int itemPosition = parent.getChildLayoutPosition(view);
        int spanCount = getSpanCount(parent);
        int childCount = parent.getAdapter().getItemCount();
//        if (isLastRaw(parent, itemPosition, spanCount, childCount))// 如果是最后一行,则不需要绘制底部
//        {
//            outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
//        }
        if (isLastColumn(parent, itemPosition, spanCount, childCount))// 如果是最后一列,则不需要绘制右边
        {
            outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
        } else {
            outRect.set(0, 0, mDivider.getIntrinsicWidth(),
                    mDivider.getIntrinsicHeight());
        }
    }
 
Example 2
Source File: GridItemDecoration.java    From BaseRecyclerViewAdapterHelper with MIT License 6 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (dividerDrawable == null) {
        return;
    }

    if (parent.getChildLayoutPosition(view) < 1) {
        return;
    }

    if (orientation == LinearLayoutManager.VERTICAL) {
        outRect.top = dividerDrawable.getIntrinsicHeight();
    } else if (orientation == LinearLayoutManager.HORIZONTAL) {
        outRect.left = dividerDrawable.getIntrinsicWidth();
    }
}
 
Example 3
Source File: DefaultItemDecoration.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent,
    @NonNull RecyclerView.State state) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        int orientation = getOrientation(layoutManager);
        int position = parent.getChildLayoutPosition(view);
        int spanCount = getSpanCount(layoutManager);
        int childCount = layoutManager.getItemCount();

        if (orientation == RecyclerView.VERTICAL) {
            offsetVertical(outRect, position, spanCount, childCount);
        } else {
            offsetHorizontal(outRect, position, spanCount, childCount);
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        outRect.set(mWidth, mHeight, mWidth, mHeight); // |-|-
    }
}
 
Example 4
Source File: CarouselItemDecoration.java    From CarouselView with MIT License 5 votes vote down vote up
@Override
public void getItemOffsets(@NonNull final Rect outRect, @NonNull final View view, @NonNull final RecyclerView parent, @NonNull final RecyclerView.State state) {
  super.getItemOffsets(outRect, view, parent, state);

  outRect.right = this.width > 0 ? this.spacing / 2 : this.spacing;
  outRect.left = this.width > 0 ? this.spacing / 2 : 0;

  if ((state.getItemCount() - 1 == parent.getChildLayoutPosition(view))) {
    outRect.right = this.width > 0 ? ((parent.getMeasuredWidth() / 2) - (this.width / 2)) : 0;
  }
  if (parent.getChildLayoutPosition(view) == 0) {
    outRect.left = this.width > 0 ? ((parent.getMeasuredWidth() / 2) - (this.width / 2)) : 0;
  }
}
 
Example 5
Source File: OnLoadMoreScrollListener.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
public boolean canTriggerLoadMore(RecyclerView recyclerView) {
    View lastChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
    int position = recyclerView.getChildLayoutPosition(lastChild);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int totalItemCount = layoutManager.getItemCount();
    return totalItemCount - 1 == position;
}
 
Example 6
Source File: SpacingItemDecorator.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                           RecyclerView.State state) {
    if (parent.getChildLayoutPosition(view) != 0) {
        if (ViewCompat.getLayoutDirection(parent) ==
                ViewCompat.LAYOUT_DIRECTION_RTL)
            outRect.right += spacing;
        else
            outRect.left += spacing;
    }
}
 
Example 7
Source File: HorizontalDecoration.java    From QuickDevFramework with Apache License 2.0 5 votes vote down vote up
@Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//        super.getItemOffsets(outRect, view, parent, state);
        int top = 0;
        if(parent.getChildLayoutPosition(view) == 0) {
            top = dividerSize;
        }
        outRect.set(0, top, 0, dividerSize);
    }
 
Example 8
Source File: ScrollSmoothLineaerLayoutManager.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    View firstVisibleChild = recyclerView.getChildAt(0);
    int itemHeight = firstVisibleChild.getHeight();
    int currentPosition = recyclerView.getChildLayoutPosition(firstVisibleChild);
    int distanceInPixels = Math.abs((currentPosition - position) * itemHeight);
    if (distanceInPixels == 0) {
        distanceInPixels = (int) Math.abs(firstVisibleChild.getY());
    }
    SmoothScroller smoothScroller = new SmoothScroller(recyclerView.getContext(), distanceInPixels, duration);
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
Example 9
Source File: HeaderItemDecoration.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    int value = (parent.getChildLayoutPosition(view) < mNumberOfChildren) ? mHeaderHeight : 0;
    if (mReversed) {
        outRect.bottom = value;
    } else {
        outRect.top = value;
    }
}
 
Example 10
Source File: GridDividerItemDecoration.java    From cloudinary_android with MIT License 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int itemPosition = parent.getChildLayoutPosition(view);
    int col = itemPosition % span;
    outRect.top = itemPosition < span ? 0 : dividerWidth;
    outRect.bottom = 0;
    outRect.right = col < span - 1 ? dividerWidth / 2 : 0;
    outRect.left = col > 0 ? dividerWidth / 2 : 0;
}
 
Example 11
Source File: EquidistantDecoration.java    From QuickDevFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = parent.getChildLayoutPosition(view);
    int[] rect = getItemOffsetRect(position, state.getItemCount());
    outRect.set(rect[0], rect[1], rect[2], rect[3]);
}
 
Example 12
Source File: DividerItemDecoration.java    From RecyclerViewExtensions with MIT License 4 votes vote down vote up
private boolean hasDivider(RecyclerView parent, View child) {
    int position = parent.getChildLayoutPosition(child);
    return position != RecyclerView.NO_POSITION && (mDividers == null || mDividers.hasDivider(position));
}