I am trying to create an ItemDecoration drawn as a divider between a RecyclerView items with left padding.
Currently I have this implementation inside ItemDecoration class:
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final RecyclerView.LayoutManager lm = parent.getLayoutManager();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
final int top = lm.getDecoratedBottom(child);
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left + 40, top, right, bottom);
mDivider.draw(c);
}
}
But it seems like the divider is still drawing itself full width. So what am I doing wrong?
I also tried setting an InsetDrawable with left insets (from xml), as the divider, but it seems like it will not draw it at all.
PS. That 40 value is just a hardcoded one, for explanatory purpose. mDivider is a Drawable.