Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何每次只滑动一张 #28

Open
ITzhangyan opened this issue Oct 13, 2018 · 5 comments
Open

如何每次只滑动一张 #28

ITzhangyan opened this issue Oct 13, 2018 · 5 comments

Comments

@ITzhangyan
Copy link

你好,3D效果如何设置每次滑动只能滑动一张,demo里可以滑动很多张,我通过设置滑动速度,但是效果不好

@yan-lixin
Copy link

@ITzhangyan 尝试了SnapHelper跟LinearSnapHelper都无效,貌似是跟自定义的LayoutManager冲突。最后自定义了RecyclerView,设置了抛掷速度的缩放因子,试了试可以解决快速滑动多张的问题。

public class CustomRecyclerView extends RecyclerView {
private double mScale;

public CustomRecyclerView(Context context) {
    super(context);
}

public CustomRecyclerView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomRecyclerView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public void setFlingScale(double scale) {
    this.mScale = scale;
}

@Override
public boolean fling(int velocityX, int velocityY) {
    velocityX *= mScale;
    return super.fling(velocityX, velocityY);
}

}

使用:mRecyclerView.setFlingScale(0.1);

@yangchong211
Copy link

@ITzhangyan @yan-lixin @renjianan 可以自定义SnapHelper就可以实现一次滑动一张卡片,具体可以https://github.com/yangchong211/YCBanner

@xilost
Copy link

xilost commented Dec 5, 2018

滑动页数是CenterSnapHelper的onFling方法里的offsetPosition控制的,将offsetPosition设置为0就是滑动一页。
int currentPosition = layoutManager.getCurrentPosition(); int offsetPosition = 0; if (layoutManager.isFling) { offsetPosition = (int) (mGravityScroller.getFinalX() / layoutManager.mInterval / layoutManager.getDistanceRatio()); } mRecyclerView.smoothScrollToPosition(layoutManager.getReverseLayout() ? currentPosition - offsetPosition : currentPosition + offsetPosition);

@yan-lixin
Copy link

@xilost isFling是在哪里定义的

@xilost
Copy link

xilost commented Dec 6, 2018

@yan-lixin 可以参考autoPlaying的定义。我是方便在xml里设置。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants