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

往下拉放大图片,不放手,直接快速往上快速一滑松开手会导致AppBarLayout错位卡位 #26

Open
mensaoselang opened this issue Aug 4, 2020 · 10 comments

Comments

@mensaoselang
Copy link

往下拉放大图片,不放手,直接快速往上快速一滑松开手会导致AppBarLayout错位卡位

@Null8889
Copy link

一样?解决了么?

@JmStefanAndroid
Copy link
Owner

你好,该问题,在我的测试机上未复现,请提供机型,以及系统版本

@Null8889
Copy link

华为荣耀 EMUI 10.0.0

@lixuce248
Copy link

在下拉动作的时候把 DisInterceptNestedScrollView的惯性滑动事件取消掉就可以 了

@kokobebekoko
Copy link

在下拉动作的时候把 DisInterceptNestedScrollView的惯性滑动事件取消掉就可以 了

你好 具体怎么操作

@Fredlxy
Copy link

Fredlxy commented Mar 7, 2022

有谁解决了这个问题吗?

@Fredlxy
Copy link

Fredlxy commented Mar 7, 2022

@OverRide
public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY) {
if (velocityY > 1000) {//当y速度>1000,就秒弹回
isAnimate = false;
if (target instanceof DisInterceptNestedScrollView){
return true;
}
}
return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
}
这样试了下,没问题了

@Qiang11
Copy link

Qiang11 commented Mar 12, 2022

@OverRide public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY) { if (velocityY > 1000) {//当y速度>1000,就秒弹回 isAnimate = false; if (target instanceof DisInterceptNestedScrollView){ return true; } } return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY); } 这样试了下,没问题了

我是试了 下还是不行

@Qiang11
Copy link

Qiang11 commented Mar 12, 2022

主要是图片在放大得时候 松手图片 使用动画恢复 如果动画在恢复过程中 在上滑 middle部分 就会错位
@Override public boolean onStartNestedScroll(@NonNull CoordinatorLayout parent, @NonNull AppBarLayout child, @NonNull View directTargetChild, View target, int nestedScrollAxes, int type) { if (isRecovering && middleLayout!= null){ middleLayout.setNestedScrollingEnabled(false); } return super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes, type); }
`private void recovery(final AppBarLayout abl) {
if (isRecovering) return;
if (mTotalDy > 0 && abl.getBottom() > mParentHeight) {
isRecovering = true;
if (isAnimate) {
ValueAnimator anim = ValueAnimator.ofFloat(mLastScale, 1f).setDuration(200);
anim.addUpdateListener(
new ValueAnimator.AnimatorUpdateListener() {
@OverRide
public void onAnimationUpdate(ValueAnimator animation) {

                            float value = (float) animation.getAnimatedValue();
                            mTargetView.setScaleY(value);
                            mTargetView.setScaleX(value);
                            abl.setBottom((int) (mLastBottom - (mLastBottom - mParentHeight) * animation.getAnimatedFraction()));
                            middleLayout.setTop((int) (mLastBottom -
                                    (mLastBottom - mParentHeight) * animation.getAnimatedFraction() - mMiddleHeight));
                            if (onProgressChangeListener != null) {
                                float progress = Math.min((value - 1) / MAX_REFRESH_LIMIT, 1);//计算0~1的进度
                                onProgressChangeListener.onProgressChange(progress, true);
                            }
                        }
                    }
            );
            anim.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    isRecovering = false;
                    mTotalDy = 0;
                    isAnimate = true;
                    if (middleLayout != null){
                        middleLayout.setNestedScrollingEnabled(true);
                    }
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                }
            });
            anim.start();
        } else {
            mTargetView.setScaleY(1f);
            mTargetView.setScaleX(1f);
            abl.setBottom(mParentHeight);
            middleLayout.setTop(mParentHeight - mMiddleHeight);
            middleLayout.setBottom(mParentHeight);


            if (onProgressChangeListener != null)
                onProgressChangeListener.onProgressChange(0, true);
            mTotalDy = 0;
            isRecovering = false;
            isAnimate = true;
            if (middleLayout != null){
                middleLayout.setNestedScrollingEnabled(true);
            }
        }

    }

}`

@Fredlxy
Copy link

Fredlxy commented Mar 14, 2022

@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed, int type) {
    if (!isRecovering && child.getBottom() >= mParentHeight) {
        if ((dy < 0 && child.getBottom() >= mParentHeight)
                || (dy > 0 && child.getBottom() > mParentHeight)) {//先放大--->后缩小的过程
            scale(child, target, dy);
            isRecyclerViewFling = false;
            return;
        }else {
            isRecyclerViewFling = true;
        }
        Log.i(TAG,"dx = " + dx + "dy = "+ dy + " consumed[0]=" + consumed[0] + "consumed[1]=" + consumed[1]);
    }else {
        isRecyclerViewFling = true;
    }
    super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
}

@OverRide
public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY) {
if(velocityY >100){
isAnimate = false;
if (target instanceof RecyclerView) {
return !isRecyclerViewFling;
}
}
return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
}

下拉的过程中屏蔽recyclerView的flying事件

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

7 participants