本文整理匯總了Java中android.support.v7.widget.RecyclerView.scrollBy方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.scrollBy方法的具體用法?Java RecyclerView.scrollBy怎麽用?Java RecyclerView.scrollBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.scrollBy方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleDragScroll
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void handleDragScroll(RecyclerView rv, DragInfo dragInfo) {
if (rv.getLayoutManager().canScrollHorizontally()) {
if (rv.canScrollHorizontally(-1) && dragInfo.shouldScrollLeft()) {
rv.scrollBy(-SCROLL_AMOUNT, 0);
dragManager.clearNextMove();
} else if (rv.canScrollHorizontally(1) && dragInfo.shouldScrollRight(rv.getWidth())) {
rv.scrollBy(SCROLL_AMOUNT, 0);
dragManager.clearNextMove();
}
} else if (rv.getLayoutManager().canScrollVertically()) {
if (rv.canScrollVertically(-1) && dragInfo.shouldScrollUp()) {
rv.scrollBy(0, -SCROLL_AMOUNT);
dragManager.clearNextMove();
} else if (rv.canScrollVertically(1) && dragInfo.shouldScrollDown(rv.getHeight())) {
rv.scrollBy(0, SCROLL_AMOUNT);
dragManager.clearNextMove();
}
}
}
示例2: scrollIfNecessary
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 當用戶滾動到邊緣的時候,計算是否需要滾動
*/
private boolean scrollIfNecessary(RecyclerView recyclerView, int curX, int curY) {
if (!isDrag) {
return false;
}
RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
int scrollX = 0;
int scrollY = 0;
if (lm.canScrollHorizontally()) {
scrollX = dragListener.calcHorizontalScrollDistance(recyclerView, curX, curY);
}
if (lm.canScrollVertically()) {
scrollY = dragListener.calcVerticalScrollDistance(recyclerView, curX, curY);
}
// System.out.println("scroll:::::" + scrollY + "=" + recyclerView.getScrollY() + "curY::" + curY);
// System.out.println("scroll:::::" + scrollX + "=" + recyclerView.getScrollX() + "curX::" + curX);
if (scrollX != 0 || scrollY != 0) {
recyclerView.scrollBy(scrollX, scrollY);
}
return scrollX != 0 || scrollY != 0;
}
示例3: onScrolled
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//在這裏進行第二次滾動(最後的100米!)
if (move) {
move = false;
//獲取要置頂的項在當前屏幕的位置,mIndex是記錄的要置頂項在RecyclerView中的位置
LinearLayoutManager mLinearLayoutManager = (LinearLayoutManager) layoutManager;
int n = mIndex - mLinearLayoutManager.findFirstVisibleItemPosition();
if (0 <= n && n < recyclerView.getChildCount()) {
//獲取要置頂的項頂部離RecyclerView頂部的距離
int top = recyclerView.getChildAt(n).getTop();
//最後的移動
recyclerView.scrollBy(0, top);
}
}
}
示例4: syncOffset
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public static boolean syncOffset(SmoothAppBarLayout smoothAppBarLayout, View target, int verticalOffset, View scroll) {
boolean isSelected = target == scroll;
if (scroll instanceof NestedScrollView) {
NestedScrollView nestedScrollView = (NestedScrollView) scroll;
if (nestedScrollView.getScrollY() < verticalOffset || (!isSelected && isScrollToTop(target))) {
nestedScrollView.scrollTo(0, verticalOffset);
}
if (isSelected && (nestedScrollView.getScrollY() < verticalOffset || verticalOffset == 0)) {
nestedScrollView.scrollTo(0, 0);
smoothAppBarLayout.syncOffset(0);
}
} else if (scroll instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) scroll;
boolean isAccuracy = recyclerView.getLayoutManager().findViewByPosition(ObservableRecyclerView.HEADER_VIEW_POSITION) != null;
if (isAccuracy && recyclerView.computeVerticalScrollOffset() < verticalOffset) {
recyclerView.scrollBy(0, verticalOffset - recyclerView.computeVerticalScrollOffset());
} else if (!isSelected && isScrollToTop(target)) {
recyclerView.scrollToPosition(ObservableRecyclerView.HEADER_VIEW_POSITION);
}
if (isAccuracy && isSelected && (recyclerView.computeVerticalScrollOffset() < verticalOffset || verticalOffset == 0)) {
recyclerView.scrollToPosition(ObservableRecyclerView.HEADER_VIEW_POSITION);
smoothAppBarLayout.syncOffset(0);
}
}
return true;
}
示例5: onTouchEvent
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
debugLog("onTouchEvent");
if ((e.getAction() == MotionEvent.ACTION_UP) ||
(e.getAction() == MotionEvent.ACTION_CANCEL)) {
if ((e.getAction() == MotionEvent.ACTION_UP) && selectedDragItemPos != -1) {
int newPos = getNewPostion(rv);
if (moveInterface != null)
moveInterface.onItemMoved(selectedDragItemPos, newPos);
}
setIsDragging(false);
selectedDragItemPos = -1;
floatingItem = null;
rv.invalidateItemDecorations();
return;
}
fingerY = (int) e.getY();
if (floatingItem != null) {
floatingItemBounds.top = fingerY - fingerOffsetInViewY;
if (floatingItemBounds.top < -floatingItemStatingBounds.height() / 2) //Allow half the view out the top
floatingItemBounds.top = -floatingItemStatingBounds.height() / 2;
floatingItemBounds.bottom = floatingItemBounds.top + floatingItemStatingBounds.height();
floatingItem.setBounds(floatingItemBounds);
}
//Do auto scrolling at end of list
float scrollAmount = 0;
if (fingerY > (rv.getHeight() * (1 - autoScrollWindow))) {
scrollAmount = (fingerY - (rv.getHeight() * (1 - autoScrollWindow)));
} else if (fingerY < (rv.getHeight() * autoScrollWindow)) {
scrollAmount = (fingerY - (rv.getHeight() * autoScrollWindow));
}
debugLog("Scroll: " + scrollAmount);
scrollAmount *= autoScrollSpeed;
rv.scrollBy(0, (int) scrollAmount);
rv.invalidateItemDecorations();// Redraw
}
示例6: performAction
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void performAction(UiController uiController, RecyclerView recyclerView) {
recyclerView.scrollBy(x, y);
}
示例7: scrollIfNecessary
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* If user drags the view to the edge, trigger a scroll if necessary.
*/
private boolean scrollIfNecessary() {
RecyclerView recyclerView = null;
if ((mRegion & IN_MAIN_REGION) != 0) {
recyclerView = mMainRecyclerView;
}
if ((mRegion & IN_SUB_REGION) != 0) {
recyclerView = mSubRecyclerView;
}
if (recyclerView == null) return false;
final long now = System.currentTimeMillis();
final long scrollDuration = mDragScrollStartTimeInMs
== Long.MIN_VALUE ? 0 : now - mDragScrollStartTimeInMs;
RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
int scrollX = 0;
int scrollY = 0;
if (lm.canScrollHorizontally()) {
int curX = (int) (mSelectedStartX + mDx);
final int leftDiff = curX - mEdgeWidth - recyclerView.getPaddingLeft();
if (mDx < 0 && leftDiff < 0) {
scrollX = leftDiff;
} else if (mDx > 0) {
final int rightDiff =
curX + mSelected.getWidth() + mEdgeWidth - (recyclerView.getWidth() - recyclerView.getPaddingRight());
if (rightDiff > 0) {
scrollX = rightDiff;
}
}
}
if (lm.canScrollVertically()) {
int curY = (int) (mSelectedStartY + mDy);
final int topDiff = curY - mEdgeWidth - recyclerView.getPaddingTop();
if (mDy < 0 && topDiff < 0) {
scrollY = topDiff;
} else if (mDy > 0) {
final int bottomDiff = curY + mSelected.getHeight() + mEdgeWidth -
(recyclerView.getHeight() - recyclerView.getPaddingBottom());
if (bottomDiff > 0) {
scrollY = bottomDiff;
}
}
}
if (scrollX != 0) {
scrollX = interpolateOutOfBoundsScroll(recyclerView,
mSelected.getWidth(), scrollX,
recyclerView.getWidth(), scrollDuration);
}
if (scrollY != 0) {
scrollY = interpolateOutOfBoundsScroll(recyclerView,
mSelected.getHeight(), scrollY,
recyclerView.getHeight(), scrollDuration);
}
if (scrollX != 0 || scrollY != 0) {
if (mDragScrollStartTimeInMs == Long.MIN_VALUE) {
mDragScrollStartTimeInMs = now;
}
recyclerView.scrollBy(scrollX, scrollY);
return true;
}
mDragScrollStartTimeInMs = Long.MIN_VALUE;
return false;
}
示例8: scrollRecyclerViewToMiddle
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void scrollRecyclerViewToMiddle(RecyclerView recyclerView, int position){
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
int left = recyclerView.getChildAt(position - layoutManager.findFirstVisibleItemPosition()).getLeft();
int right = recyclerView.getChildAt(layoutManager.findLastVisibleItemPosition() - position).getLeft();
recyclerView.scrollBy((left - right)/2,0);
}