android - RecyclerView with more that one row per item doesn't inflate divider -
i have recyclerview's here , there , found when list item have 1 row divideritemdecoration
works fine, when comes two-rows items doesn't show up.
here inflate it:
cenalistrecadapter madapter = new cenalistrecadapter(getapplicationcontext(), cenalokallist, point); recyclerview.setadapter(madapter); recyclerview.additemdecoration(new divideritemdecoration(getapplicationcontext(),divideritemdecoration.vertical_list));
and standard divideritemdecoration
class:
public class divideritemdecoration extends recyclerview.itemdecoration { private static final int[] attrs = new int[]{ android.r.attr.listdivider }; public static final int horizontal_list = linearlayoutmanager.horizontal; public static final int vertical_list = linearlayoutmanager.vertical; private drawable mdivider; private int morientation; public divideritemdecoration(context context, int orientation) { final typedarray = context.obtainstyledattributes(attrs); mdivider = a.getdrawable(0); a.recycle(); setorientation(orientation); } public void setorientation(int orientation) { if (orientation != horizontal_list && orientation != vertical_list) { throw new illegalargumentexception("invalid orientation"); } morientation = orientation; } @override public void ondraw(canvas c, recyclerview parent) { if (morientation == vertical_list) { drawvertical(c, parent); } else { drawhorizontal(c, parent); } } public void drawvertical(canvas c, recyclerview parent) { final int left = parent.getpaddingleft(); final int right = parent.getwidth() - parent.getpaddingright(); final int childcount = parent.getchildcount(); (int = 0; < childcount; i++) { final view child = parent.getchildat(i); final recyclerview.layoutparams params = (recyclerview.layoutparams) child .getlayoutparams(); final int top = child.getbottom() + params.bottommargin; final int bottom = top + mdivider.getintrinsicheight(); mdivider.setbounds(left, top, right, bottom); mdivider.draw(c); } } public void drawhorizontal(canvas c, recyclerview parent) { final int top = parent.getpaddingtop(); final int bottom = parent.getheight() - parent.getpaddingbottom(); final int childcount = parent.getchildcount(); (int = 0; < childcount; i++) { final view child = parent.getchildat(i); final recyclerview.layoutparams params = (recyclerview.layoutparams) child .getlayoutparams(); final int left = child.getright() + params.rightmargin; final int right = left + mdivider.getintrinsicheight(); mdivider.setbounds(left, top, right, bottom); mdivider.draw(c); } } @override public void getitemoffsets(rect outrect, int itemposition, recyclerview parent) { if (morientation == vertical_list) { outrect.set(0, 0, 0, mdivider.getintrinsicheight()); } else { outrect.set(0, 0, mdivider.getintrinsicwidth(), 0); } }
}
edit: that's how row view item looks like:
<?xml version="1.0" encoding="utf-8"?> <linearlayout android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_margintop="5dp" android:layout_marginbottom="5dp" android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android" > <imageview android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/imageview" android:transitionname="obrazek" android:layout_marginright="5dp" /> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingtop="5dp" android:paddingbottom="5dp" android:background="?android:attr/selectableitembackground"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="medium text" android:id="@+id/nazwa" android:maxlines="1" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="medium text" android:id="@+id/odleglosc" android:layout_gravity="right" android:gravity="end" android:layout_below="@+id/nazwa" android:layout_alignparentright="true" android:layout_alignparentend="true" android:clickable="false" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text=" " android:id="@+id/cena" android:layout_below="@+id/nazwa" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> </relativelayout> </linearlayout>`
this might of help, official documentation:
all itemdecorations drawn in order added, before item views, in
itemdecoration#ondraw()
, after items initemdecoration#ondrawover(canvas, recyclerview, recyclerview.state)
you should overriding ondrawover
method instead.
Comments
Post a Comment