本文整理汇总了Java中android.support.v7.widget.RecyclerView.LayoutManager.canScrollHorizontally方法的典型用法代码示例。如果您正苦于以下问题:Java LayoutManager.canScrollHorizontally方法的具体用法?Java LayoutManager.canScrollHorizontally怎么用?Java LayoutManager.canScrollHorizontally使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.RecyclerView.LayoutManager
的用法示例。
在下文中一共展示了LayoutManager.canScrollHorizontally方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMoved
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
public void onMoved(RecyclerView recyclerView, ViewHolder viewHolder, int fromPos, ViewHolder target, int toPos, int x, int y) {
LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof ViewDropHandler) {
((ViewDropHandler) layoutManager).prepareForDrop(viewHolder.itemView, target.itemView, x, y);
return;
}
if (layoutManager.canScrollHorizontally()) {
if (layoutManager.getDecoratedLeft(target.itemView) <= recyclerView.getPaddingLeft()) {
recyclerView.scrollToPosition(toPos);
}
if (layoutManager.getDecoratedRight(target.itemView) >= recyclerView.getWidth() - recyclerView.getPaddingRight()) {
recyclerView.scrollToPosition(toPos);
}
}
if (layoutManager.canScrollVertically()) {
if (layoutManager.getDecoratedTop(target.itemView) <= recyclerView.getPaddingTop()) {
recyclerView.scrollToPosition(toPos);
}
if (layoutManager.getDecoratedBottom(target.itemView) >= recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
recyclerView.scrollToPosition(toPos);
}
}
}
示例2: findSwipedView
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
private ViewHolder findSwipedView(MotionEvent motionEvent) {
LayoutManager lm = this.mRecyclerView.getLayoutManager();
if (this.mActivePointerId == -1) {
return null;
}
int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, this.mActivePointerId);
float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - this.mInitialTouchY;
float absDx = Math.abs(MotionEventCompat.getX(motionEvent, pointerIndex) - this.mInitialTouchX);
float absDy = Math.abs(dy);
if (absDx < ((float) this.mSlop) && absDy < ((float) this.mSlop)) {
return null;
}
if (absDx > absDy && lm.canScrollHorizontally()) {
return null;
}
if (absDy > absDx && lm.canScrollVertically()) {
return null;
}
View child = findChildView(motionEvent);
if (child != null) {
return this.mRecyclerView.getChildViewHolder(child);
}
return null;
}
示例3: calculateDxToMakeVisible
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
public int calculateDxToMakeVisible(View view, int snapPreference) {
LayoutManager layoutManager = getLayoutManager();
if (layoutManager == null || !layoutManager.canScrollHorizontally()) {
return 0;
}
LayoutParams params = (LayoutParams) view.getLayoutParams();
return calculateDtToFit(layoutManager.getDecoratedLeft(view) - params.leftMargin, layoutManager.getDecoratedRight(view) + params.rightMargin, layoutManager.getPaddingLeft(), layoutManager.getWidth() - layoutManager.getPaddingRight(), snapPreference);
}
示例4: scrollIfNecessary
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
private boolean scrollIfNecessary() {
if (this.mSelected == null) {
this.mDragScrollStartTimeInMs = Long.MIN_VALUE;
return false;
}
long scrollDuration;
long now = System.currentTimeMillis();
if (this.mDragScrollStartTimeInMs == Long.MIN_VALUE) {
scrollDuration = 0;
} else {
scrollDuration = now - this.mDragScrollStartTimeInMs;
}
LayoutManager lm = this.mRecyclerView.getLayoutManager();
if (this.mTmpRect == null) {
this.mTmpRect = new Rect();
}
int scrollX = 0;
int scrollY = 0;
lm.calculateItemDecorationsForChild(this.mSelected.itemView, this.mTmpRect);
if (lm.canScrollHorizontally()) {
int curX = (int) (this.mSelectedStartX + this.mDx);
int leftDiff = (curX - this.mTmpRect.left) - this.mRecyclerView.getPaddingLeft();
if (this.mDx < 0.0f && leftDiff < 0) {
scrollX = leftDiff;
} else if (this.mDx > 0.0f) {
int rightDiff = ((this.mSelected.itemView.getWidth() + curX) + this.mTmpRect.right) - (this.mRecyclerView.getWidth() - this.mRecyclerView.getPaddingRight());
if (rightDiff > 0) {
scrollX = rightDiff;
}
}
}
if (lm.canScrollVertically()) {
int curY = (int) (this.mSelectedStartY + this.mDy);
int topDiff = (curY - this.mTmpRect.top) - this.mRecyclerView.getPaddingTop();
if (this.mDy < 0.0f && topDiff < 0) {
scrollY = topDiff;
} else if (this.mDy > 0.0f) {
int bottomDiff = ((this.mSelected.itemView.getHeight() + curY) + this.mTmpRect.bottom) - (this.mRecyclerView.getHeight() - this.mRecyclerView.getPaddingBottom());
if (bottomDiff > 0) {
scrollY = bottomDiff;
}
}
}
if (scrollX != 0) {
scrollX = this.mCallback.interpolateOutOfBoundsScroll(this.mRecyclerView, this.mSelected.itemView.getWidth(), scrollX, this.mRecyclerView.getWidth(), scrollDuration);
}
if (scrollY != 0) {
scrollY = this.mCallback.interpolateOutOfBoundsScroll(this.mRecyclerView, this.mSelected.itemView.getHeight(), scrollY, this.mRecyclerView.getHeight(), scrollDuration);
}
if (scrollX == 0 && scrollY == 0) {
this.mDragScrollStartTimeInMs = Long.MIN_VALUE;
return false;
}
if (this.mDragScrollStartTimeInMs == Long.MIN_VALUE) {
this.mDragScrollStartTimeInMs = now;
}
this.mRecyclerView.scrollBy(scrollX, scrollY);
return true;
}
示例5: findTargetSnapPosition
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
/***
* Well composition does not work so we copy this method from {@link LinearSnapHelper}.
* That sucks!
*
* @param layoutManager
* @param velocityX
* @param velocityY
* @return
*/
@Override
public int findTargetSnapPosition(final LayoutManager layoutManager, final int velocityX, final int velocityY) {
if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return RecyclerView.NO_POSITION;
}
final int itemCount = layoutManager.getItemCount();
if (itemCount == 0) {
return RecyclerView.NO_POSITION;
}
final View currentView = findSnapView(layoutManager);
if (currentView == null) {
return RecyclerView.NO_POSITION;
}
final int currentPosition = layoutManager.getPosition(currentView);
if (currentPosition == RecyclerView.NO_POSITION) {
return RecyclerView.NO_POSITION;
}
RecyclerView.SmoothScroller.ScrollVectorProvider vectorProvider =
(RecyclerView.SmoothScroller.ScrollVectorProvider) layoutManager;
// deltaJumps sign comes from the velocity which may not match the order of children in
// the LayoutManager. To overcome this, we ask for a vector from the LayoutManager to
// get the direction.
PointF vectorForEnd = vectorProvider.computeScrollVectorForPosition(itemCount - 1);
if (vectorForEnd == null) {
// cannot get a vector for the given position.
return RecyclerView.NO_POSITION;
}
int vDeltaJump, hDeltaJump;
if (layoutManager.canScrollHorizontally()) {
hDeltaJump = estimateNextPositionDiffForFling(layoutManager,
getHorizontalHelper(layoutManager), velocityX, 0);
if (vectorForEnd.x < 0) {
hDeltaJump = -hDeltaJump;
}
} else {
hDeltaJump = 0;
}
if (layoutManager.canScrollVertically()) {
vDeltaJump = estimateNextPositionDiffForFling(layoutManager,
getVerticalHelper(layoutManager), 0, velocityY);
if (vectorForEnd.y < 0) {
vDeltaJump = -vDeltaJump;
}
} else {
vDeltaJump = 0;
}
int deltaJump = layoutManager.canScrollVertically() ? vDeltaJump : hDeltaJump;
if (deltaJump == 0) {
return RecyclerView.NO_POSITION;
}
int targetPos = currentPosition + deltaJump;
if (targetPos < 0) {
targetPos = 0;
}
if (targetPos >= itemCount) {
targetPos = itemCount - 1;
}
return targetPos;
}
示例6: calculateDistanceToFinalSnap
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
/**
* Override this method to snap to a particular point within the target view or the container
* view on any axis.
* <p>
* This method is called when the {@link SnapHelper} has intercepted a fling and it needs
* to know the exact distance required to scroll by in order to snap to the target view.
*
* @param layoutManager the {@link RecyclerView.LayoutManager} associated with the attached
* {@link RecyclerView}
* @param targetView the target view that is chosen as the view to snap
*
* @return the output coordinates the put the result into. out[0] is the distance
* on horizontal axis and out[1] is the distance on vertical axis.
*/
@Nullable
@Override
public int[] calculateDistanceToFinalSnap(@NonNull final LayoutManager layoutManager, @NonNull final View targetView) {
int[] out = new int[2];
out[0] = layoutManager.canScrollHorizontally() ? getXCoordinateToSnapPos(layoutManager, targetView) : 0;
out[1] = layoutManager.canScrollVertically() ? getYCoordinateToSnapPos(layoutManager, targetView) : 0;
return out;
}