I'm tring to make smooth scroller to need position in recyclerView. I'm ovverride method smoothScrollToPosition in LinearLayoutManager, and it's work fine. But, I need to set scrolled position on top of screen(if is possible). I also tried scrollToPositionWithOffset, and it's make that I need, but now, without smooth effect. How to mix this methods, and make smooth scroll with set item on top?
private LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this){
@Override
public void smoothScrollToPosition(RecyclerView recyclerView,
RecyclerView.State state, final int position) {
LinearSmoothScroller smoothScroller =
new LinearSmoothScroller(getApplicationContext()) {
//This controls the direction in which smoothScroll looks
//for your view
@Override
public PointF computeScrollVectorForPosition
(int targetPosition) {
return this
.computeScrollVectorForPosition(targetPosition);
}
//This returns the milliseconds it takes to
//scroll one pixel.
@Override
protected float calculateSpeedPerPixel
(DisplayMetrics displayMetrics) {
return 50f/displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
};