I have a recycler view... and i want a smooth scrolldown and then scrollup to it programatically to show the complete content in it to user .... And i m able to do this by<
I've made a version that you can set the scrolling speed variable.
If you set factor to 2, it will be twice as slow as default.
public class VariableScrollSpeedLinearLayoutManager extends LinearLayoutManager {
private final float factor;
public VariableScrollSpeedLinearLayoutManager(Context context, float factor) {
super(context);
this.factor = factor;
}
@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 VariableScrollSpeedLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return super.calculateSpeedPerPixel(displayMetrics) * factor;
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
}