forked from huazhiyuan2008/RecyclerViewCardGallery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
library/src/main/java/com/view/jameson/library/CardLinearSnapHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.view.jameson.library; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.LinearSnapHelper; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
|
||
/** | ||
* 防止卡片在第一页和最后一页因无法"居中"而一直循环调用onScrollStateChanged-->SnapHelper.snapToTargetExistingView-->onScrollStateChanged | ||
* Created by jameson on 9/3/16. | ||
*/ | ||
public class CardLinearSnapHelper extends LinearSnapHelper { | ||
public boolean mNoNeedToScroll = false; | ||
|
||
@Override | ||
public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView) { | ||
if (mNoNeedToScroll) { | ||
return new int[]{0, 0}; | ||
} else { | ||
return super.calculateDistanceToFinalSnap(layoutManager, targetView); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters