Java 类android.support.v7.widget.LinearSmoothScroller 实例源码
项目:Sticky-Header-Grid
文件:StickyHeaderGridLayoutManager.java
@Override
public void smoothScrollToPosition(final RecyclerView recyclerView, RecyclerView.State state, int position) {
final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public int calculateDyToMakeVisible(View view, int snapPreference) {
final RecyclerView.LayoutManager layoutManager = getLayoutManager();
if (layoutManager == null || !layoutManager.canScrollVertically()) {
return 0;
}
final int adapterPosition = getPosition(view);
final int topOffset = getPositionSectionHeaderHeight(adapterPosition);
final int top = layoutManager.getDecoratedTop(view);
final int bottom = layoutManager.getDecoratedBottom(view);
final int start = layoutManager.getPaddingTop() + topOffset;
final int end = layoutManager.getHeight() - layoutManager.getPaddingBottom();
return calculateDtToFit(top, bottom, start, end, snapPreference);
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
项目:RecyclerWheelPicker
文件:WheelPickerLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
@Nullable
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return WheelPickerLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:Farmacias
文件:ScrollerLinearLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
//
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext){
@Nullable
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return ScrollerLinearLayoutManager.this.computeScrollVectorForPosition
(targetPosition);
}
//1 pixel -> 0.05 ms
//1000 pixel -> x=50 ms to go over the height of the screen
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return 0.05f;
//return x /displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:pager-layoutmanager
文件:PagerGridSnapHelper.java
/**
* 通过自定义 LinearSmoothScroller 来控制速度
*
* @param layoutManager 布局故哪里去
* @return 自定义 LinearSmoothScroller
*/
protected LinearSmoothScroller createSnapScroller(RecyclerView.LayoutManager layoutManager) {
if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return null;
}
return new LinearSmoothScroller(mRecyclerView.getContext()) {
@Override
protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
int[] snapDistances = calculateDistanceToFinalSnap(mRecyclerView.getLayoutManager(),
targetView);
final int dx = snapDistances[0];
final int dy = snapDistances[1];
Logi("dx = " + dx);
Logi("dy = " + dy);
final int time = calculateTimeForDeceleration(Math.max(Math.abs(dx), Math.abs(dy)));
if (time > 0) {
action.update(dx, dy, time, mDecelerateInterpolator);
}
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
}
项目:GridPagerSnapHelper
文件:SnapHelper.java
/**
* Creates a scroller to be used in the snapping implementation.
*
* @param layoutManager The {@link RecyclerView.LayoutManager} associated with the attached
* {@link RecyclerView}.
* @return a {@link LinearSmoothScroller} which will handle the scrolling.
*/
@Nullable
protected LinearSmoothScroller createSnapScroller(RecyclerView.LayoutManager layoutManager) {
if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return null;
}
return new LinearSmoothScroller(mRecyclerView.getContext()) {
@Override
protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
int[] snapDistances = calculateDistanceToFinalSnap(mRecyclerView.getLayoutManager(),
targetView);
final int dx = snapDistances[0];
final int dy = snapDistances[1];
final int time = calculateTimeForDeceleration(Math.max(Math.abs(dx), Math.abs(dy)));
if (time > 0) {
action.update(dx, dy, time, mDecelerateInterpolator);
}
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
}
项目:diycode
文件:SpeedyLinearLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int
position) {
final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView
.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition
(targetPosition);
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
项目:Capsule
文件:SGridLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScroller linearSmoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
if (scrollSpeed != null) {
float speed = scrollSpeed.calculateSpeedPerPixel(super.calculateSpeedPerPixel(displayMetrics));
scrollSpeed = null;
return speed;
}
return super.calculateSpeedPerPixel(displayMetrics);
}
@Nullable
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return super.computeScrollVectorForPosition(targetPosition);
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
项目:Capsule
文件:SLinearLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScroller linearSmoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
if (scrollSpeed != null) {
float speed = scrollSpeed.calculateSpeedPerPixel(super.calculateSpeedPerPixel(displayMetrics));
scrollSpeed = null;
return speed;
}
return super.calculateSpeedPerPixel(displayMetrics);
}
@Nullable
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return SLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
项目:Radio2
文件:CustomLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {
//This controls the direction in which smoothScroll looks
//for your view
@Override
public PointF computeScrollVectorForPosition
(int targetPosition) {
return CustomLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
//This returns the milliseconds it takes to
//scroll one pixel.
@Override
protected float calculateSpeedPerPixel (DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH/displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:xDrip
文件:ActivityWithRecycler.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return CustomLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
linearSmoothScroller.setTargetPosition(position);
try {
startSmoothScroll(linearSmoothScroller);
} catch (IllegalArgumentException e) {
// couldn't scroll for some reason, just ignore
}
}
项目:xDrip-plus
文件:ActivityWithRecycler.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return CustomLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
linearSmoothScroller.setTargetPosition(position);
try {
startSmoothScroll(linearSmoothScroller);
} catch (IllegalArgumentException e) {
// couldn't scroll for some reason, just ignore
}
}
项目:yield
文件:ToDayView.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView,
RecyclerView.State state,
int position) {
RecyclerView.SmoothScroller smoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return AgendaLinearLayoutManager.this
.computeScrollVectorForPosition(targetPosition);
}
@Override
protected int getVerticalSnapPreference() {
return SNAP_TO_START; // override base class behavior
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:Musique
文件:CustomGridLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {
//This controls the direction in which smoothScroll looks
//for your view
@Override
public PointF computeScrollVectorForPosition
(int targetPosition) {
return CustomGridLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
//This returns the milliseconds it takes to
//scroll one pixel.
@Override
protected float calculateSpeedPerPixel (DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH/displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:Musique
文件:CustomLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {
//This controls the direction in which smoothScroll looks
//for your view
@Override
public PointF computeScrollVectorForPosition
(int targetPosition) {
return CustomLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
//This returns the milliseconds it takes to
//scroll one pixel.
@Override
protected float calculateSpeedPerPixel (DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH/displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:toshi-android-client
文件:SpeedyLinearLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
if (position < 0) {
return;
}
final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
项目:materialistic
文件:SnappyLinearLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView,
RecyclerView.State state,
int position) {
RecyclerView.SmoothScroller smoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return SnappyLinearLayoutManager.this
.computeScrollVectorForPosition(targetPosition);
}
@Override
protected int getVerticalSnapPreference() {
return SNAP_TO_START; // override base class behavior
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:Ouroboros
文件:SnappyLinearLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
final LinearSmoothScroller linearSmoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
// I want a behavior where the scrolling always snaps to the beginning of
// the list. Snapping to end is also trivial given the default implementation.
// If you need a different behavior, you may need to override more
// of the LinearSmoothScrolling methods.
protected int getHorizontalSnapPreference() {
return SNAP_TO_START;
}
protected int getVerticalSnapPreference() {
return SNAP_TO_START;
}
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return SnappyLinearLayoutManager.this
.computeScrollVectorForPosition(targetPosition);
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
项目:qksms
文件:SmoothLinearLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
super.smoothScrollToPosition(recyclerView, state, position);
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {
//This controls the direction in which smoothScroll looks for your view
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return new PointF(0, 1);
}
//This returns the milliseconds it takes to scroll one pixel.
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:RecyclerView-AbsoluteLayoutManager
文件:AbsoluteLayoutManager.java
public void smoothScrollToPositionWithAlignment(Context context, int position, final int scrollAlignment) {
if (!isAttachedToWindow()) {
// NOTE: startSmoothScroll() references mRecyclerView and it will crash when RecyclerView
// is not attached to LayoutManager.
scrollToPositionWithAlignment(position, scrollAlignment);
return;
}
LinearSmoothScroller linearSmoothScroller = new CenterAwareLinearSmoothScroller(context, scrollAlignment) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
prepareLayoutProvider();
Point targetScrollOffset = calculateScrollOffsetToShowPositionIfPossible(targetPosition, scrollAlignment);
if (targetScrollOffset == null) return null;
normalizeScrollOffset(targetScrollOffset);
return ScrollHelper.calculateUnitVectorFromPoints(mCurrentScrollOffset, targetScrollOffset);
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
项目:buseta
文件:LwbStopListFragment.java
@Override
public boolean onMarkerClick(Marker marker) {
if (marker.getTag() instanceof BusRouteStop) {
BusRouteStop stop = (BusRouteStop) marker.getTag();
if (stop != null) {
if (recyclerView != null) {
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
smoothScroller.setTargetPosition(Integer.parseInt(stop.sequence));
recyclerView.getLayoutManager().startSmoothScroll(smoothScroller);
}
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(Double.parseDouble(stop.latitude), Double.parseDouble(stop.longitude)), 16));
Intent intent = new Intent(getContext(), EtaService.class);
intent.putExtra(C.EXTRA.STOP_OBJECT, stop);
getContext().startService(intent);
}
}
return true;
}
项目:buseta
文件:KmbStopListFragment.java
@Override
public boolean onMarkerClick(Marker marker) {
if (marker.getTag() instanceof BusRouteStop) {
BusRouteStop stop = (BusRouteStop) marker.getTag();
if (stop != null) {
if (recyclerView != null) {
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
smoothScroller.setTargetPosition(Integer.parseInt(stop.sequence));
recyclerView.getLayoutManager().startSmoothScroll(smoothScroller);
}
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(Double.parseDouble(stop.latitude), Double.parseDouble(stop.longitude)), 16));
Intent intent = new Intent(getContext(), EtaService.class);
intent.putExtra(C.EXTRA.STOP_OBJECT, stop);
getContext().startService(intent);
}
}
return true;
}
项目:yield
文件:ToDayView.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView,
RecyclerView.State state,
int position) {
RecyclerView.SmoothScroller smoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return AgendaLinearLayoutManager.this
.computeScrollVectorForPosition(targetPosition);
}
@Override
protected int getVerticalSnapPreference() {
return SNAP_TO_START; // override base class behavior
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:photon-tinker-android
文件:EventsFragment.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
项目:GitHub
文件:CustomLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
position = Math.max(position, 0);
position = Math.min(position, self.getItemCount());
/*
* LinearSmoothScroller's default behavior is to scroll the contents until
* the child is fully visible. It will snap to the top-left or bottom-right
* of the parent depending on whether the direction of travel was positive
* or negative.
*/
LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
/*
* 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 oldScrollX = self.getState().scrolledX;
int oldScrollY = self.getState().scrolledY;
self.getState().scrolledX = self.getState().itemsFrames.get(targetPosition).left;
self.getState().scrolledY = self.getState().itemsFrames.get(targetPosition).top;
self.fixScrollOffset();
int newScrollX = self.getState().scrolledX;
int newScrollY = self.getState().scrolledY;
self.getState().scrolledX = oldScrollX;
self.getState().scrolledY = oldScrollY;
return new PointF(newScrollX - oldScrollX, newScrollY - oldScrollY);
}
};
scroller.setTargetPosition(position);
self.startSmoothScroll(scroller);
}
项目:android_ui
文件:CalendarView.java
/**
*/
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) {
if (scroller == null) {
this.scroller = new LinearSmoothScroller(recyclerView.getContext()) {
/**
*/
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return LayoutManagerImpl.this.computeScrollVectorForPosition(targetPosition);
}
/**
*/
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return scrollSpeedPerInch / displayMetrics.densityDpi;
}
/**
*/
@Override
protected int calculateTimeForScrolling(int dx) {
return dx != 0 ? Math.max(super.calculateTimeForScrolling(dx), 50) : 0;
}
};
}
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
项目:SimpleBible
文件:ReadFragment.java
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_read, container, false);
RecyclerView mRecyclerView = view.findViewById(R.id.versesRecyclerView);
mAdapter = new VersesAdapter();
mLayoutManager = mRecyclerView.getLayoutManager();
mRecyclerView.setAdapter(mAdapter);
//preload the versions
//new DBTRetriever().getBooks(getContext());
//new DBTRetriever().getVersions(getContext());
Activity activity = getActivity();
if (activity == null) {
return view;
}
mSmoothScroller = new LinearSmoothScroller(activity) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
mBookChapterView = activity.findViewById(R.id.selected_book);
mTranslationView = activity.findViewById(R.id.selected_translation);
setAppBarDisplay();
return view;
}
项目:gradle-module-dependency
文件:FixedGridLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
if (position >= getItemCount()) {
Log.e(TAG, "Cannot scroll to "+position+", item count is "+getItemCount());
return;
}
/*
* LinearSmoothScroller's default behavior is to scroll the contents until
* the child is fully visible. It will snap to the top-left or bottom-right
* of the parent depending on whether the direction of travel was positive
* or negative.
*/
LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
/*
* 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) {
final int rowOffset = getGlobalRowOfPosition(targetPosition)
- getGlobalRowOfPosition(mFirstVisiblePosition);
final int columnOffset = getGlobalColumnOfPosition(targetPosition)
- getGlobalColumnOfPosition(mFirstVisiblePosition);
return new PointF(columnOffset * mDecoratedChildWidth, rowOffset * mDecoratedChildHeight);
}
};
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
项目:SnakeRecyclerViewExample
文件:SnakeGridLayoutManager.java
@Override
public void smoothScrollToPosition(
RecyclerView recyclerView, RecyclerView.State state, int position) {
if (position >= getItemCount()) position = getItemCount() - 1;
LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
final int rowOffset = getRowIndex(targetPosition) - firstVisibleRow;
return new PointF(0, rowOffset * cellHeight);
}
};
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
项目:react-native-recyclerview-list
文件:RecyclerViewBackedScrollView.java
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);
}
项目:cardslider-android
文件:CardSliderLayoutManager.java
@Override
public void smoothScrollToPosition(final RecyclerView recyclerView, RecyclerView.State state, final int position) {
if (position < 0 || position >= getItemCount()) {
return;
}
final LinearSmoothScroller scroller = getSmoothScroller(recyclerView);
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
项目:cardslider-android
文件:CardSliderLayoutManager.java
public LinearSmoothScroller getSmoothScroller(final RecyclerView recyclerView) {
return new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public int calculateDxToMakeVisible(View view, int snapPreference) {
final int viewStart = getDecoratedLeft(view);
if (viewStart > activeCardLeft) {
return activeCardLeft - viewStart;
} else {
int delta = 0;
int topViewPos = 0;
final View topView = getTopView();
if (topView != null) {
topViewPos = getPosition(topView);
if (topViewPos != getTargetPosition()) {
final int topViewLeft = getDecoratedLeft(topView);
if (topViewLeft >= activeCardLeft && topViewLeft < activeCardRight) {
delta = activeCardRight - topViewLeft;
}
}
}
return delta + (cardWidth) * Math.max(0, topViewPos - getTargetPosition() - 1);
}
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return 0.5f;
}
};
}
项目:ChipsLayoutManager
文件:HorizontalScrollingController.java
@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());
}
};
}
项目:ChipsLayoutManager
文件:VerticalScrollingController.java
@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());
}
};
}
项目:PicShow-zhaipin
文件:RecyclerIndicatorView.java
private void smoothScrollToPosition(int position, final int offeset) {
LinearSmoothScroller linearSmoothScroller =
new LinearSmoothScroller(getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
PointF pointF = linearLayoutManager
.computeScrollVectorForPosition(targetPosition);
pointF.x += offeset;
return pointF;
}
};
linearSmoothScroller.setTargetPosition(position);
linearLayoutManager.startSmoothScroll(linearSmoothScroller);
}
项目:Here
文件:SpannedGridLayoutManager.java
@Override
public void smoothScrollToPosition(
RecyclerView recyclerView, RecyclerView.State state, int position) {
if (position >= getItemCount()) position = getItemCount() - 1;
LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
final int rowOffset = getRowIndex(targetPosition) - firstVisibleRow;
return new PointF(0, rowOffset * cellHeight);
}
};
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
项目:MusicX-music-player
文件:CustomLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {
//This controls the direction in which smoothScroll looks
//for your view
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return CustomLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
@Override
protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
//This returns the milliseconds it takes to
//scroll one pixel.
@Override
protected float calculateSpeedPerPixel
(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
项目:RetroMusicPlayer
文件:SpannedGridLayoutManager.java
@Override
public void smoothScrollToPosition(
RecyclerView recyclerView, RecyclerView.State state, int position) {
if (position >= getItemCount()) position = getItemCount() - 1;
LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
final int rowOffset = getRowIndex(targetPosition) - firstVisibleRow;
return new PointF(0, rowOffset * cellHeight);
}
};
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
项目:AvatarTinderView
文件:SpannedGridLayoutManager.java
@Override
public void smoothScrollToPosition(
RecyclerView recyclerView, RecyclerView.State state, int position) {
if (position >= getItemCount()) position = getItemCount() - 1;
LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
final int rowOffset = getRowIndex(targetPosition) - firstVisibleRow;
return new PointF(0, rowOffset * cellHeight);
}
};
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
项目:Blockbuster
文件:TwoWayLayoutManager.java
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) {
final LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
if (getChildCount() == 0) {
return null;
}
final int direction = targetPosition < getFirstVisiblePosition() ? -1 : 1;
if (mIsVertical) {
return new PointF(0, direction);
} else {
return new PointF(direction, 0);
}
}
@Override
protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
@Override
protected int getHorizontalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}
项目:android-multipleGridRecyclerView-library
文件:SpannedGridLayoutManager.java
@Override
public void smoothScrollToPosition(
RecyclerView recyclerView, RecyclerView.State state, int position) {
if (position >= getItemCount()) position = getItemCount() - 1;
LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
final int rowOffset = getRowIndex(targetPosition) - firstVisibleRow;
return new PointF(0, rowOffset * cellHeight);
}
};
scroller.setTargetPosition(position);
startSmoothScroll(scroller);
}