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

CoverFlowLayoutManger中mSlectPositon计算存在bug #18

Open
WhySRZ opened this issue Jun 11, 2020 · 2 comments
Open

CoverFlowLayoutManger中mSlectPositon计算存在bug #18

WhySRZ opened this issue Jun 11, 2020 · 2 comments

Comments

@WhySRZ
Copy link

WhySRZ commented Jun 11, 2020

CoverFlowLayoutManger中mSlectPositon计算存在bug
private void onSelectedCallBack() {
mSelectPosition = Math.round (mOffsetAll / getIntervalDistance());
mSelectPosition = Math.abs(mSelectPosition % getItemCount());
if (mSelectedListener != null && mSelectPosition != mLastSelectPosition) {
mSelectedListener.onItemSelected(mSelectPosition);
}
mLastSelectPosition = mSelectPosition;
}

当mSelectPositon为负数时,会出现位置对不上,比如我有5个条目,当mSelectPosition为-6,Math.abs(mSelectPosition % getItemCount())计算结果为1,但事实对应的条目应该是4,当mSelectPosition为负数时正确的位置计算应该为应为
mSelectPosition = 条目个数和(list.size())+mSelectPosition % getItemCount()

@zt80hou
Copy link

zt80hou commented Sep 18, 2021

list.size())+mSelectPosition % getItemCount()

牛逼,但是还有一种偶现情况 为负数的时候,计算完mSelectPosition =getItemCount(),此时应该置位0,还需要再优化。
image

@zt80hou
Copy link

zt80hou commented Sep 18, 2021

/**
* 计算当前选中位置,并回调
*/
private void onSelectedCallBack() {
mSelectPosition = Math.round(mOffsetAll / getIntervalDistance());
Log.e("mSelectPosition", "mSelectPosition = " + mSelectPosition);
if (mSelectPosition < 0) {
mSelectPosition = getItemCount() + mSelectPosition % getItemCount();
} else {
mSelectPosition = Math.abs(mSelectPosition % getItemCount());
}
if (mSelectPosition == getItemCount()) {// 偶现相等
Log.e("mSelectPosition", "偶现相等 ");
mSelectPosition = 0;
}
if (mSelectedListener != null && mSelectPosition != mLastSelectPosition) {
mSelectedListener.onItemSelected(mSelectPosition);
}
mLastSelectPosition = mSelectPosition;
}

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

2 participants