Back to project page android-test-demo.
The source code is released under:
MIT License
If you think the Android project android-test-demo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.andydyer.androidtestdemo.ui.widgets; /* ww w.ja v a 2s . com*/ import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.support.v7.widget.RecyclerView; import android.view.View; import org.andydyer.androidtestdemo.R; /** * https://gist.github.com/polbins/e37206fbc444207c0e92 */ public class SimpleDividerItemDecoration extends RecyclerView.ItemDecoration { private Drawable mDivider; public SimpleDividerItemDecoration(Context context) { mDivider = context.getResources().getDrawable(R.drawable.line_divider); } @Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); int top = child.getBottom() + params.bottomMargin; int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } }