Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SingleDividerDecoration extends DividerItemDecoration {
- private final int height;
- private int position = -1;
- public SingleDividerDecoration(Context context, @DrawableRes int dividerId) {
- super(context, LinearLayout.VERTICAL);
- Drawable divider = ContextCompat.getDrawable(context, dividerId);
- this.height = divider.getIntrinsicHeight();
- setDrawable(divider);
- }
- public void setPosition(int position) {
- this.position = position;
- }
- @Override
- public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
- int viewPosition = parent.getChildAdapterPosition(view);
- int dividerHeight = viewPosition == position ? height : 0;
- outRect.set(0, 0, 0, dividerHeight);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement