整个的item的背景是白色,特意设置imgView 的高度不填充item 。左右的黄色的间隔是由于设置rect.left/rect.right

具体的代码:
item.xml(http://www.amjmh.com/v/)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/white"
android:gravity="center_vertical">

<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="60dp" />
</LinearLayout>
1
2
3
4
5
6
7
8
9
10
11
12
自定义LinearItemDecoration

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {


outRect.left = space;
outRect.right = space;
outRect.bottom = space ;
// Add top margin only for the first item to avoid double space between items
// if (parent.getChildPosition(view) == 0)
// outRect.top = space;
}
————————————————

posted @ 2019-08-28 22:18  李艳艳665  阅读(185)  评论(0编辑  收藏  举报