RecycleView+自定义滚动条
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//整体的总宽度,注意是整体,包括在显示区域之外的。
int temp = recyclerView.computeHorizontalScrollRange();
if (temp > range) {
range = temp;
}
//计算水平滚动的距离
int offset = recyclerView.computeHorizontalScrollOffset();
//计算水平滚动的范围
int extent = recyclerView.computeHorizontalScrollExtent();
//计算滑动比例
float proportion = (float) (offset * 1.0 / (range - extent));
//计算滚动条宽度
float transMaxRange = line.getWidth() - mainLine.getWidth();
//设置滚动条移动
mainLine.setTranslationX(transMaxRange * proportion);
// Log.e("scrll", transMaxRange + "---" + range + "---" + "---" + proportion + "---" + offset + "----" + extent);
}