lsjwzh / RecyclerViewPager

Deprecated
Apache License 2.0
3.53k stars 667 forks source link

左右滑动跳页 #156

Open oybo opened 7 years ago

oybo commented 7 years ago

作者您好,我这发现有比较大的概率,左右一直滑动,突然像放电影一样一直往前翻,到第0页,不知道是什么问题。

yichunyen commented 7 years ago

@oybo I had the same issue when I used the Horizontal Recycler View. If you do not use the loop recycler view, please check the RecyclerViewPager.java line 510. The targetPosition sometimes will return 0 if you scroll fast. I solved it since remarked all codes about targetPosition.

Good luck.

oybo commented 7 years ago

@yichunyen Thank you very much. According to what you say, I added a judgment in smoothScrollToPosition method public void smoothScrollToPosition(int position) { if (mType == PageType.horizontal) { // This is my own if(Math.abs(getCurrentPosition() - position) != 1) { return; } } ..... But don't know if I can completely solve the problem, Could you tell me how do you solve?

yichunyen commented 7 years ago

@oybo This is my fixed codes that I forked from this.

oybo commented 7 years ago

@yichunyen Thank you, hello, I found that there are still problems, can appear targetPosition return 0. So I add a judgment :

public void smoothScrollToPosition(int position) {
    if (DEBUG) {
        Log.d("@", "smoothScrollToPosition:" + position);
    }

    if (mPositionBeforeScroll < 0) {
        mPositionBeforeScroll = getCurrentPosition();
    }
if(Math.abs(position - getCurrentPosition()) > 1) {
        position = getCurrentPosition();
    }
    mSmoothScrollTargetPosition = position;
yichunyen commented 7 years ago

@oybo How did you reproduce your issues? Currently, it seldom occurs in my project.

que123567 commented 2 years ago

横滑的情况下,修改一下ViewUtils类的这个方法

 public static int getCenterXChildPosition(RecyclerView recyclerView) {
        int childCount = recyclerView.getChildCount();
        if (childCount > 0) {
            for (int i = 0; i < childCount; i++) {
                View child = recyclerView.getChildAt(i);
                 //这个接口有时会一直返回false,导致最后return childCount,所以就回到了某个固定页
                if (isChildInCenterX(recyclerView, child)) {
                    return recyclerView.getChildAdapterPosition(child);
                }
            }
             //只添加这行就可以修复这个问题
            return recyclerView.getChildAdapterPosition(recyclerView.getChildAt(0));
        }

        return childCount;
  }
que123567 commented 2 years ago

@oybo How did you reproduce your issues? Currently, it seldom occurs in my project.

Using your left hand slide it to right and at the same time use your right hand to slide it to the left side.(The orientation of view is horizontal)