本文整理匯總了Java中android.support.v7.widget.RecyclerView.SmoothScroller方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.SmoothScroller方法的具體用法?Java RecyclerView.SmoothScroller怎麽用?Java RecyclerView.SmoothScroller使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.SmoothScroller方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: snapFromFling
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 快速滾動的具體處理方案
*
* @param layoutManager 布局管理器
* @param velocityX X 軸滾動速率
* @param velocityY Y 軸滾動速率
* @return 是否消費該事件
*/
private boolean snapFromFling(@NonNull RecyclerView.LayoutManager layoutManager, int velocityX,
int velocityY) {
if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return false;
}
RecyclerView.SmoothScroller smoothScroller = createSnapScroller(layoutManager);
if (smoothScroller == null) {
return false;
}
int targetPosition = findTargetSnapPosition(layoutManager, velocityX, velocityY);
if (targetPosition == RecyclerView.NO_POSITION) {
return false;
}
smoothScroller.setTargetPosition(targetPosition);
layoutManager.startSmoothScroll(smoothScroller);
return true;
}
示例2: snapFromFling
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Helper method to facilitate for snapping triggered by a fling.
*
* @param layoutManager The {@link RecyclerView.LayoutManager} associated with the attached
* {@link RecyclerView}.
* @param velocityX Fling velocity on the horizontal axis.
* @param velocityY Fling velocity on the vertical axis.
* @return true if it is handled, false otherwise.
*/
private boolean snapFromFling(@NonNull RecyclerView.LayoutManager layoutManager, int velocityX,
int velocityY) {
if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return false;
}
RecyclerView.SmoothScroller smoothScroller = createSnapScroller(layoutManager);
if (smoothScroller == null) {
return false;
}
int targetPosition = findTargetSnapPosition(layoutManager, velocityX, velocityY);
if (targetPosition == RecyclerView.NO_POSITION) {
return false;
}
smoothScroller.setTargetPosition(targetPosition);
layoutManager.startSmoothScroll(smoothScroller);
return true;
}
示例3: smoothScrollToPosition
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void smoothScrollToPosition(int position, final ScrollOptions options) {
final RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(this.getContext()) {
@Override
protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return ((LinearLayoutManager) this.getLayoutManager()).computeScrollVectorForPosition(targetPosition);
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
if (options.millisecondsPerInch != null) {
return options.millisecondsPerInch / displayMetrics.densityDpi;
} else {
return super.calculateSpeedPerPixel(displayMetrics);
}
}
@Override
public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) {
int calc = super.calculateDtToFit(viewStart, viewEnd, boxStart, boxEnd, snapPreference);
if (options.viewPosition != null) {
int viewHeight = viewEnd - viewStart;
int boxHeight = boxEnd - boxStart;
float viewOffset = options.viewOffset != null ? PixelUtil.toPixelFromDIP(options.viewOffset) : 0;
float target = boxStart + (boxHeight - viewHeight) * options.viewPosition + viewOffset;
return (int) (target - viewStart);
} else {
return super.calculateDtToFit(viewStart, viewEnd, boxStart, boxEnd, snapPreference);
}
}
};
smoothScroller.setTargetPosition(position);
this.getLayoutManager().startSmoothScroll(smoothScroller);
}
示例4: createSmoothScroller
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public RecyclerView.SmoothScroller createSmoothScroller(@NonNull Context context, final int position, final int timeMs, final AnchorViewState anchor) {
return new LinearSmoothScroller(context) {
/*
* LinearSmoothScroller, at a minimum, just need to know the vector
* (x/y distance) to travel in order to get from the current positioning
* to the target.
*/
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
int visiblePosition = anchor.getPosition();
//determine scroll up or scroll down needed
return new PointF(position > visiblePosition ? 1 : -1, 0);
}
@Override
protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
super.onTargetFound(targetView, state, action);
int currentLeft = layoutManager.getPaddingLeft();
int desiredLeft = layoutManager.getDecoratedLeft(targetView);
int dx = desiredLeft - currentLeft;
//perform fit animation to move target view at top of layoutX
action.update(dx, 0, timeMs, new LinearInterpolator());
}
};
}
示例5: smoothScrollToPosition
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
if (position >= getItemCount() || position < 0) {
Log.e("span layout manager", "Cannot scroll to " + position + ", item count " + getItemCount());
return;
}
RecyclerView.SmoothScroller scroller = scrollingController.createSmoothScroller(recyclerView.getContext(), position, 150, anchorView);
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
示例6: createSmoothScroller
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public RecyclerView.SmoothScroller createSmoothScroller(@NonNull Context context, final int position, final int timeMs, final AnchorViewState anchor) {
return new LinearSmoothScroller(context) {
/*
* LinearSmoothScroller, at a minimum, just need to know the vector
* (x/y distance) to travel in order to get from the current positioning
* to the target.
*/
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
int visiblePosition = anchor.getPosition();
//determine scroll up or scroll down needed
return new PointF(0, position > visiblePosition ? 1 : -1);
}
@Override
protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
super.onTargetFound(targetView, state, action);
int desiredTop = lm.getPaddingTop();
int currentTop = lm.getDecoratedTop(targetView);
int dy = currentTop - desiredTop;
//perform fit animation to move target view at top of layout
action.update(0, dy, timeMs, new LinearInterpolator());
}
};
}
示例7: smoothScrollToPosition
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(final RecyclerView recyclerView,
final RecyclerView.State state,
final int position) {
RecyclerView.SmoothScroller smoothScroller =
new CenterSmoothScroller(recyclerView.getContext());
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
示例8: createSmoothScroller
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
RecyclerView.SmoothScroller createSmoothScroller(@NonNull Context context, int position, int timeMs, AnchorViewState anchor);