ChenLittlePing / RecyclerCoverFlow

使用RecyclerView,自定义LayoutManager实现旋转木马相册效果
Apache License 2.0
829 stars 152 forks source link

调用smoothScrollPosition滚动指定位置,会出现回滚到原来位置 #19

Open CTSN opened 4 years ago

CTSN commented 4 years ago

你好,我用的平板横屏调试demo,出现这个问题。 我debug看了下, 位置0->位置1,正常调用smoothScrollToPosition 位置1->位置2,调用smoothScrollToPosition同时会调用scrollHorizontallyBy,导致mOffsetAll重新计算,导致滚动失败。 我尝试着在scrollHorizontallyBy 和 fixOffsetWhenFinishScroll方法里加个判断,return出去不触发,恢复正常使用。具体原因分析不出来。 我的修改: ` @Override public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) { if (isSmoothScroll){ Log.e("isSmoothScroll" , "return"); return 0; } if (mAnimation != null && mAnimation.isRunning()) mAnimation.cancel(); int travel = dx; if (!mIsLoop) { //非循环模式,限制滚动位置 if (dx + mOffsetAll < 0) { travel = -mOffsetAll; } else if (dx + mOffsetAll > getMaxOffset()){ travel = (int) (getMaxOffset() - mOffsetAll); } } mOffsetAll += travel; //累计偏移量 layoutItems(recycler, state, dx > 0 ? SCROLL_TO_LEFT : SCROLL_TO_RIGHT); return travel; } /**

@Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { // TODO 循环模式暂不支持平滑滚动

    if (mIsLoop) return;
    int finalOffset = calculateOffsetForPosition(position);
    if (mRecycle == null || mState == null) {//如果RecyclerView还没初始化完,先记录下要滚动的位置
        mSelectPosition = position;
    } else {
        startScroll(mOffsetAll, finalOffset);
        isSmoothScroll = true;
    }
}

`

lxb89 commented 3 years ago

请问,如何控制滑动速度,无论慢滑还是快滑都只滑动一个item,而不是将数据集全部滑动一遍