private void smoothScrollToX(int finalLeft) { if (viewDragHelper.settleCapturedViewAt(finalLeft, 0)) { ViewCompat.postInvalidateOnAnimation(SwipeBackLayout.this); } }
private void smoothScrollToY(int finalTop) { if (viewDragHelper.settleCapturedViewAt(0, finalTop)) { ViewCompat.postInvalidateOnAnimation(SwipeBackLayout.this); } }
@Override public void onViewReleased(@NonNull View releasedChild, float xvel, float yvel) { final int childWidth = releasedChild.getWidth(); final int childHeight = releasedChild.getHeight(); int left = 0, top = 0; if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_LEFT) != 0) { left = xvel > 0 || xvel == 0 && mScrollPercent > SCROLL_FINISH_THRESHOLD ? (childWidth) : 0; } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_RIGHT) != 0) { left = xvel < 0 || xvel == 0 && mScrollPercent > SCROLL_FINISH_THRESHOLD ? -(childWidth) : 0; } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_TOP) != 0) { top = yvel < 0 || yvel == 0 && mScrollPercent > SCROLL_FINISH_THRESHOLD ? (childHeight) : 0; } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_BOTTOM) != 0) { top = yvel < 0 || yvel == 0 && mScrollPercent > SCROLL_FINISH_THRESHOLD ? -(childHeight) : 0; } mDragHelper.settleCapturedViewAt(left, top); invalidate(); } }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { final int childWidth = releasedChild.getWidth(); final int childHeight = releasedChild.getHeight(); // 计算 ContentView 最终滑动目标 left 和 top // 这里说明下 xvel 和 yvel,他俩的取值范围为系统判断触摸滑动fling事件的最大和最小滑动速率,小于 mMinVelocity 统统返回0 int left = 0, top = 0; if ((mTrackingEdge & EDGE_LEFT) != 0) { left = xvel > 0 || xvel == 0 && mScrollPercent > mScrollThreshold ? childWidth + mShadowLeft.getIntrinsicWidth() + OVER_SCROLL_DISTANCE : 0; } else if ((mTrackingEdge & EDGE_RIGHT) != 0) { left = xvel < 0 || xvel == 0 && mScrollPercent > mScrollThreshold ? -(childWidth + mShadowLeft.getIntrinsicWidth() + OVER_SCROLL_DISTANCE) : 0; } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { top = yvel < 0 || yvel == 0 && mScrollPercent > mScrollThreshold ? -(childHeight + mShadowBottom.getIntrinsicHeight() + OVER_SCROLL_DISTANCE) : 0; } // 让拖拽视图滑动到指定位置 mDragHelper.settleCapturedViewAt(left, top); invalidate(); }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); mDragHelper.settleCapturedViewAt(0, 0); ViewCompat.postInvalidateOnAnimation(FriendRefreshView.this); //如果手势释放时,拖动的距离大于rainbowStickyTop,开始刷新 if (currentTop >= rainbowStickyTop) { startRefresh(); } } });
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { int left = Math.abs(xvel) < FLING_MIN_VELOCITY ? positionHelper.getLeftToSettle(dragProgress, maxDragDistance) : positionHelper.getLeftAfterFling(xvel, maxDragDistance); dragHelper.settleCapturedViewAt(left, rootView.getTop()); invalidate(); }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); if (mCurEdgeFlag == ViewDragHelper.EDGE_LEFT) { if (mCurrentX > getWidth() / 2) { mViewDragHelper.settleCapturedViewAt(getWidth(), 0); } else { mViewDragHelper.settleCapturedViewAt(0, 0); mCurrentX = 0; } invalidate(); } }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { final LayoutParams lp = (LayoutParams) releasedChild.getLayoutParams(); int left; if (isLayoutRtlSupport()) { int startToRight = getPaddingRight() + lp.rightMargin; if (xvel < 0 || (xvel == 0 && mSlideOffset > mSwipeBackThreshold)) { startToRight += mSlideRange; } int childWidth = mSlideableView.getWidth(); left = getWidth() - startToRight - childWidth; } else { left = getPaddingLeft() + lp.leftMargin; if (xvel > 0 || (xvel == 0 && mSlideOffset > mSwipeBackThreshold)) { left += mSlideRange; } } mDragHelper.settleCapturedViewAt(left, releasedChild.getTop()); invalidate(); }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { int slop = yvel > minimumFlingVelocity ? getHeight() / 6 : getHeight() / 3; if (releasedChild.getTop() > slop) { if (callback != null) { callback.onPullComplete(); } } else { if (callback != null) { callback.onPullCancel(); } dragger.settleCapturedViewAt(0, 0); invalidate(); } }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { if (releasedChild == mContentView) { if (xvel > mSlideOutVelocity) { mDragHelper.settleCapturedViewAt(mScreenWidth, 0); invalidate(); return; } if (mContentView.getLeft() < mSlideOutRange) { mDragHelper.settleCapturedViewAt(0, 0); } else { mDragHelper.settleCapturedViewAt(mScreenWidth, 0); } invalidate(); } }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { final LayoutParams lp = (LayoutParams) releasedChild.getLayoutParams(); int left; left = getPaddingLeft() + lp.leftMargin; if (xvel > 0 || (xvel == 0 && mSlideOffset > 0.5f)) { left += mSlideRange; } mDragHelper.settleCapturedViewAt(left, releasedChild.getTop()); invalidate(); }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { final LayoutParams lp = (LayoutParams) releasedChild.getLayoutParams(); int left; left = getPaddingLeft() + lp.leftMargin; if (xvel > 0 || (xvel == 0 && mSlideOffset > 0.5f)) { left += mSlideRange; } mDragHelper.settleCapturedViewAt(left, releasedChild.getTop()); invalidate(); }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { // 默认关闭,接下来再判断为打开时的条件 int finalLeft = getPaddingLeft() + mTopLp.leftMargin; if (mSwipeDirection == SwipeDirection.Left) { // 向左滑动为打开,向右滑动为关闭 if (xvel < -VEL_THRESHOLD || (mPreStatus == Status.Closed && xvel < VEL_THRESHOLD && mDragRatio >= 0.3f) || (mPreStatus == Status.Opened && xvel < VEL_THRESHOLD && mDragRatio >= 0.7f)) { // 向左的速度达到条件 finalLeft -= mDragRange; } } else { // 向左滑动为关闭,向右滑动为打开 if (xvel > VEL_THRESHOLD || (mPreStatus == Status.Closed && xvel > -VEL_THRESHOLD && mDragRatio >= 0.3f) || (mPreStatus == Status.Opened && xvel > -VEL_THRESHOLD && mDragRatio >= 0.7f)) { finalLeft += mDragRange; } } mDragHelper.settleCapturedViewAt(finalLeft, getPaddingTop() + mTopLp.topMargin); // 要执行下面的代码,不然不会自动收缩完毕或展开完毕 ViewCompat.postInvalidateOnAnimation(SwipeItemLayout.this); }
@Override public void onViewReleased(@NonNull View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); int viewWidth = releasedChild.getWidth(); int viewHeight = releasedChild.getHeight(); int curLeft = releasedChild.getLeft(); int curTop = releasedChild.getTop(); int finalLeft = margin; int finalTop = curTop < margin ? margin : curTop; if ((curLeft + viewWidth / 2) > screenWidth / 2) { finalLeft = screenWidth - viewWidth - margin; } if ((finalTop + viewHeight) > getHeight()) { finalTop = getHeight() - viewHeight - margin; } dragHelper.settleCapturedViewAt(finalLeft, finalTop); invalidate(); } });
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { int slop = yvel > minimumFlingVelocity ? getHeight() / 6 : getHeight() / 3; if (releasedChild.getTop() > slop) { if (callback != null) { callback.onPullComplete(); } } else { if (callback != null) { callback.onPullCancel(); } dragger.settleCapturedViewAt(0, 0); invalidate(); } }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { //手指释放时回调 float movePrecent = (releasedChild.getHeight() + releasedChild.getTop()) / (float) releasedChild.getHeight(); int finalTop = (xvel >= 0 && movePrecent > 0.5f) ? 0 : -releasedChild.getHeight(); mTopViewDragHelper.settleCapturedViewAt(releasedChild.getLeft(), finalTop); invalidate(); }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { //当松手后让其自动滚过去 if (releasedChild == mTopView) { int finalLeft = (xvel > 0 && mCurMovePrecent < 0.5) ? mBottomView.getMeasuredWidth() : 0; mHelper.settleCapturedViewAt(finalLeft, mTopView.getTop()); invalidate(); } } }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { int top = (yvel < 0 && mBottomViewTop < mTopView.getHeight()/2) ? 0 : mTopView.getMeasuredHeight(); mHelper.settleCapturedViewAt(mBottomView.getLeft(), top); postInvalidate(); }
@Override public void onViewReleased(@NonNull View releasedChild, float xvel, float yvel) { final int childWidth = releasedChild.getWidth(); int left = xvel > 0 || (xvel == 0 && mScrollPercent > mScrollThreshold) ? childWidth : 0; mDragHelper.settleCapturedViewAt(left, 0); invalidate(); }
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); mDragHelper.settleCapturedViewAt(0, 0); ViewCompat.postInvalidateOnAnimation(MomentsView.this); //如果手势释放时,拖动的距离大于rainbowStickyTop,开始刷新 if (currentTop >= rainbowStickyTop) { startRefresh(); } } });