Android RecyclerView设置上下左右item间距的方法非常,只需要在RecyclerView设置完adapter之后,再设置一下ItemDecoration即可,代码如下:
myRecycleView.setAdapter(simpleAdapter); RecyclerView.ItemDecoration decoration = new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); outRect.right = 10; outRect.left = 10; outRect.top = 10; outRect.bottom = 10; } }; myRecycleView.addItemDecoration(decoration);