Я пытаюсь сделать гладкий скроллер нужным положением в recyclerView. Я использую метод ovverride smoothScrollToPosition в LinearLayoutManager, и он отлично работает. Но мне нужно установить прокручиваемую позицию сверху экрана (если это возможно). Я также попробовал scrollToPositionWithOffset, и это делает то, что мне нужно, но теперь без плавного эффекта. Как смешать эти методы и сделать гладкий свиток с установленным элементом сверху?RecyclerView smooth scroll
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);
}
};
звуки, похожие на этот http://stackoverflow.com/questions/7202193/scroll-up- a-scrollview-медленно/27028101 # 27028101 Возможно, такой же подход можно использовать здесь – Muzikant