RecyclerView项目装饰

时间:2015-04-09 13:06:35

标签: android android-recyclerview

我有一个带有GridLayoutManager的RecyclerView。

我设置了自定义ItemDecoration:

public class ListDetailsItemDecoration extends RecyclerView.ItemDecoration { 
      private int space;

      public ListDetailsItemDecoration(int space) {
        this.space = space;
      } 

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

        int itemPosition = parent.getChildPosition(view);

        outRect.left = space;
        outRect.right = space;
        outRect.bottom = space;

        if(itemPosition == 0 || itemPosition == 1) {
            outRect.top = space;
        }

        if(itemPosition % 2 == 0) {
            outRect.right = space / 2;
        } else {
            outRect.left = space / 2;
        }


      } 

}

在我需要移除任何人之前,它很有用。

notifyItemRemoved(position);

网格未调整大小。

有什么想法吗?

0 个答案:

没有答案