public static OrientationHelper createHorizontalHelper(
RecyclerView.LayoutManager layoutManager) {
return new OrientationHelper(layoutManager) {
.....
@Override
public int getStartAfterPadding() {
return mLayoutManager.getPaddingLeft();
}
// mLayoutManager.getDecoratedMeasuredWidth(view)
// 获取的宽度是view的测量宽度+ Decorated(装饰的左右边框)的大小
// 还得加上view的layout_marginRight 和 layout_marginLeft
// 这个宽度由内而外 依次是 view的宽度, view的margin边距, 装饰框的偏移宽度
@Override
public int getDecoratedMeasurement(View view) {
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
view.getLayoutParams();
return mLayoutManager.getDecoratedMeasuredWidth(view) + params.leftMargin
+ params.rightMargin;
}
// 这个方法就是mLayoutManager.getDecoratedMeasuredWidth(view)
// public int getDecoratedMeasuredWidth(View child) {
// final Rect insets = ((LayoutParams)
// child.getLayoutParams()).mDecorInsets;
// view测量宽度 装饰边框的左侧宽度 装饰边框的右侧宽度
// return child.getMeasuredWidth() + insets.left + insets.right;
// }
@Override
public int getDecoratedMeasurementInOther(View view) {
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
view.getLayoutParams();
return mLayoutManager.getDecoratedMeasuredHeight(view) + params.topMargin
+ params.bottomMargin;
}
@Override
public int getTotalSpace() {
return mLayoutManager.getWidth() - mLayoutManager.getPaddingLeft()
- mLayoutManager.getPaddingRight();
}
.......
};
}