Skip to content

Commit

Permalink
fix problem with item decorator without header
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Rovkin committed Feb 18, 2015
1 parent 3ae747e commit 1b59365
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected void onCreate(Bundle savedInstanceState)

adapter = new ExampleAdapter(this, recyclerView);
adapter.setParallaxListener(this);
adapter.setEnableHeader(true);

final RecyclerView.LayoutManager layoutManager = getLayoutManager();
recyclerView.setLayoutManager(layoutManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

/**
Expand All @@ -15,6 +16,7 @@ public class SpacesItemDecoration extends RecyclerView.ItemDecoration
private int space;
private int spanCount = 1;
private boolean ignoreFirst = false;
private int positionDifference = 1;

public SpacesItemDecoration(int space)
{
Expand All @@ -34,18 +36,19 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle
if (ignoreFirst && targetPosition == 0)
return;

int positionInColumn = getPositionInColumn(targetPosition);
int positionInColumn = getPositionInColumn(targetPosition + positionDifference);

outRect.left = getLeftSpace(positionInColumn);
outRect.right = getRightSpace(positionInColumn);
outRect.top = space;

//Log.d("SpacesItemDecoration", String.format("targetPosition = %d positionInColumn = %d, left = %d right = %d", targetPosition, positionInColumn, outRect.left, outRect.right));
Log.d("SpacesItemDecoration", String.format("targetPosition = %d positionInColumn = %d, left = %d right = %d", targetPosition, positionInColumn, outRect.left, outRect.right));
}

public void setIgnoreFirst(final boolean ignoreFirst)
{
this.ignoreFirst = ignoreFirst;
positionDifference = ignoreFirst ? 0 : 1;
}

private int getPositionInColumn(int targetPosition)
Expand Down

0 comments on commit 1b59365

Please sign in to comment.