From 1b59365e7ef00cf25329407e02760c30bfd8654e Mon Sep 17 00:00:00 2001 From: Max Rovkin Date: Wed, 18 Feb 2015 18:08:55 +0500 Subject: [PATCH] fix problem with item decorator without header --- .../pro/useit/paralaxrecycleradapter/AdapterActivity.java | 1 + .../java/pro/useit/paralaxheader/SpacesItemDecoration.java | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/pro/useit/paralaxrecycleradapter/AdapterActivity.java b/app/src/main/java/pro/useit/paralaxrecycleradapter/AdapterActivity.java index cefad93..0067bb1 100644 --- a/app/src/main/java/pro/useit/paralaxrecycleradapter/AdapterActivity.java +++ b/app/src/main/java/pro/useit/paralaxrecycleradapter/AdapterActivity.java @@ -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); diff --git a/easyrecycler/src/main/java/pro/useit/paralaxheader/SpacesItemDecoration.java b/easyrecycler/src/main/java/pro/useit/paralaxheader/SpacesItemDecoration.java index 24dbcf3..dd51ea9 100644 --- a/easyrecycler/src/main/java/pro/useit/paralaxheader/SpacesItemDecoration.java +++ b/easyrecycler/src/main/java/pro/useit/paralaxheader/SpacesItemDecoration.java @@ -2,6 +2,7 @@ import android.graphics.Rect; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.View; /** @@ -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) { @@ -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)