本文整理汇总了Java中android.support.v4.widget.ScrollerCompat.computeScrollOffset方法的典型用法代码示例。如果您正苦于以下问题:Java ScrollerCompat.computeScrollOffset方法的具体用法?Java ScrollerCompat.computeScrollOffset怎么用?Java ScrollerCompat.computeScrollOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.widget.ScrollerCompat
的用法示例。
在下文中一共展示了ScrollerCompat.computeScrollOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import android.support.v4.widget.ScrollerCompat; //导入方法依赖的package包/类
@Override
public void run() {
if (mRecyclerView == null)
return;
final RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
if (layoutManager == null) {
stop();
return; // no layout, cannot scroll.
}
disableRunOnAnimationRequests();
// keep a local reference so that if it is changed during onAnimation method, it won't
// cause unexpected behaviors
final ScrollerCompat scroller = mScroller;
if (scroller.computeScrollOffset()) {
final int x = scroller.getCurrX();
final int y = scroller.getCurrY();
final int dx = x - mLastFlingX;
final int dy = y - mLastFlingY;
mLastFlingX = x;
mLastFlingY = y;
if (dx != 0 || dy != 0)
mRecyclerView.scrollBy(dx, dy);
if (scroller.isFinished()) {
if (layoutManager instanceof PagingLayoutManager) {
((PagingLayoutManager) layoutManager).onFlingFinish();
}
} else {
postOnAnimation();
}
}
enableRunOnAnimationRequests();
}
示例2: run
import android.support.v4.widget.ScrollerCompat; //导入方法依赖的package包/类
@Override
public void run() {
disableRunOnAnimationRequests();
consumePendingUpdateOperations();
// keep a local reference so that if it is changed during onAnimation method, it wont cause
// unexpected behaviors
final ScrollerCompat scroller = mScroller;
final SmoothScroller smoothScroller = mLayout.mSmoothScroller;
if (scroller.computeScrollOffset()) {
final int x = scroller.getCurrX();
final int y = scroller.getCurrY();
final int dx = x - mLastFlingX;
final int dy = y - mLastFlingY;
mLastFlingX = x;
mLastFlingY = y;
int overscrollX = 0, overscrollY = 0;
if (mAdapter != null) {
eatRequestLayout();
if (dx != 0) {
final int hresult = mLayout.scrollHorizontallyBy(dx, mRecycler, mState);
overscrollX = dx - hresult;
}
if (dy != 0) {
final int vresult = mLayout.scrollVerticallyBy(dy, mRecycler, mState);
overscrollY = dy - vresult;
}
if (smoothScroller != null && !smoothScroller.isPendingInitialRun() &&
smoothScroller.isRunning()) {
smoothScroller.onAnimation(dx - overscrollX, dy - overscrollY);
}
resumeRequestLayout(false);
}
if (!mItemDecorations.isEmpty()) {
invalidate();
}
if (overscrollX != 0 || overscrollY != 0) {
final int vel = (int) scroller.getCurrVelocity();
int velX = 0;
if (overscrollX != x) {
velX = overscrollX < 0 ? -vel : overscrollX > 0 ? vel : 0;
}
int velY = 0;
if (overscrollY != y) {
velY = overscrollY < 0 ? -vel : overscrollY > 0 ? vel : 0;
}
if (ViewCompat.getOverScrollMode(RecyclerView.this) !=
ViewCompat.OVER_SCROLL_NEVER) {
absorbGlows(velX, velY);
}
if ((velX != 0 || overscrollX == x || scroller.getFinalX() == 0) &&
(velY != 0 || overscrollY == y || scroller.getFinalY() == 0)) {
scroller.abortAnimation();
}
}
if (mScrollListener != null && (x != 0 || y != 0)) {
mScrollListener.onScrolled(dx, dy);
}
if (!awakenScrollBars()) {
invalidate();
}
if (scroller.isFinished()) {
setScrollState(SCROLL_STATE_IDLE);
} else {
postOnAnimation();
}
}
// call this after the onAnimation is complete not to have inconsistent callbacks etc.
if (smoothScroller != null && smoothScroller.isPendingInitialRun()) {
smoothScroller.onAnimation(0, 0);
}
enableRunOnAnimationRequests();
}