关于RecylerView:1.在ScrollView的RecylerView滑动事件的处理。2.item之间的距离 小数取整

1.在ScrollView的RecylerView滑动事件的处理。

在布局文件中在RecylerView外包裹一层相对布局

2.RecylerView item之间的距离

(1)编写SpaceItemDecoration

 /**
* 设置RecycleView Item之间的间距的类
*/
class SpaceItemDecoration extends RecyclerView.ItemDecoration {
int mSpace;

/**
* Retrieve any offsets for the given item. Each field of <code>outRect</code> specifies
* the number of pixels that the item view should be inset by, similar to padding or margin.
* The default implementation sets the bounds of outRect to 0 and returns.
* <p>
* <p>
* If this ItemDecoration does not affect the positioning of item views, it should set
* all four fields of <code>outRect</code> (left, top, right, bottom) to zero
* before returning.
* <p>
* <p>
* If you need to access Adapter for additional data, you can call
* {@link RecyclerView#getChildAdapterPosition(View)} to get the adapter position of the
* View.
*
* @param outRect Rect to receive the output.
* @param view The child view to decorate
* @param parent RecyclerView this ItemDecoration is decorating
* @param state The current state of RecyclerView.
// */
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
outRect.left = mSpace;
outRect.right = mSpace;
outRect.bottom = mSpace;
if (parent.getChildAdapterPosition(view) == 0) {
outRect.top = mSpace;
}

}

public SpaceItemDecoration(int space) {
this.mSpace = space;
}
}
(2)rv_home_local.addItemDecoration(new SpaceItemDecoration(15));

3.小数取整

Android中Math类中提供了三个与取整有关的方法:


分别是ceil、floor、round,这些方法的作用与它们的英文名称的含义相对应


ceil的英文解释是天花板,该方法就表示向上取整,所以,Math.ceil(16.2)的结果为17,Math.ceil(-16.2)的结果是-16;


floor的英文解释是地板,所以该方法就表示向下取整,那么Math.floor(16.6)的结果为16,Math.floor(-16.6)的结果是-17;


round方法比前两个稍微复杂一点,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,Math.round(16.2)的结果为16,Math.round(-16.2)的结果为-16.



原文地址:https://www.cnblogs.com/kim-liu/p/7495543.html