Skip to content

Instantly share code, notes, and snippets.

@twiceyuan
Last active May 12, 2016 07:25
Show Gist options
  • Save twiceyuan/9f9e7b6e7b6a05c84836cd1763bc9832 to your computer and use it in GitHub Desktop.
Save twiceyuan/9f9e7b6e7b6a05c84836cd1763bc9832 to your computer and use it in GitHub Desktop.
RecyclerView 中间分隔间隙的实现方法
// 间隔为1
mRecyclerView.addItemDecoration(new VerticalItemDecoration(DP.dp2px(getContext(), 1)));
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
* Created by twiceYuan on 3/30/16.
* Email: [email protected]
* Site: http://twiceyuan.com
*
* RecyclerView 分割线高度设定
*/
public class VerticalItemDecoration extends RecyclerView.ItemDecoration {
private final int mVerticalSpaceHeight;
public VerticalItemDecoration(int mVerticalSpaceHeight) {
this.mVerticalSpaceHeight = mVerticalSpaceHeight;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
outRect.bottom = mVerticalSpaceHeight;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment