Skip to content

Commit

Permalink
Merge pull request #11 from alex-gutierrez/master
Browse files Browse the repository at this point in the history
Use ParalaxImageView height instead of row height
  • Loading branch information
yayaa committed Feb 2, 2017
2 parents 273ba08 + 0c3bbb0 commit efb17b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Expand Up @@ -23,7 +23,6 @@ public class ParallaxImageView extends ImageView {
private boolean needToTranslate = true;
private ParallaxImageListener listener;

private int rowHeight = -1;
private int rowYPos = -1;
private int recyclerViewHeight = -1;
private int recyclerViewYPos = -1;
Expand Down Expand Up @@ -151,24 +150,24 @@ private boolean getValues() {
if (values == null)
return false;

this.rowHeight = values[0];
this.rowYPos = values[1];
this.recyclerViewHeight = values[2];
this.recyclerViewYPos = values[3];
this.rowYPos = values[0];
this.recyclerViewHeight = values[1];
this.recyclerViewYPos = values[2];
return true;
}

private void calculateAndMove() {
float distanceFromCenter = (recyclerViewYPos + recyclerViewHeight) / 2 - rowYPos;

int imageHeight = getDrawable().getIntrinsicHeight();
int drawableHeight = getDrawable().getIntrinsicHeight();
int imageViewHeight = getMeasuredHeight();
float scale = 1;
if (shouldCenterCrop) {
scale = recomputeImageMatrix();
imageHeight *= scale;
drawableHeight *= scale;
}

float difference = imageHeight - rowHeight;
float difference = drawableHeight - imageViewHeight;
float move = (distanceFromCenter / recyclerViewHeight) * difference * parallaxRatio;

moveTo((move / 2) - (difference / 2), scale);
Expand Down
Expand Up @@ -44,7 +44,10 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

for (int i = 0; i < recyclerView.getChildCount(); i++) {
((ParallaxViewHolder) recyclerView.getChildViewHolder(recyclerView.getChildAt(i))).animateImage();
ViewHolder viewHolder = recyclerView.getChildViewHolder(recyclerView.getChildAt(i));
if (viewHolder instanceof ParallaxViewHolder) {
((ParallaxViewHolder) viewHolder).animateImage();
}
}

if (scrollListener != null)
Expand Down
Expand Up @@ -31,7 +31,7 @@ public int[] requireValuesForTranslate() {
int[] recyclerPosition = new int[2];
((RecyclerView) itemView.getParent()).getLocationOnScreen(recyclerPosition);

return new int[]{itemView.getMeasuredHeight(), itemPosition[1], ((RecyclerView) itemView.getParent()).getMeasuredHeight(), recyclerPosition[1]};
return new int[]{itemPosition[1], ((RecyclerView) itemView.getParent()).getMeasuredHeight(), recyclerPosition[1]};
}
}

Expand Down

0 comments on commit efb17b2

Please sign in to comment.