zoukankan      html  css  js  c++  java
  • 关于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.



  • 相关阅读:
    ios开发,NSFileManager的使用
    iOS开发-常用第三方开源框架介绍(绝对够你用了)
    iOS开发常用第三方开源框架
    对佛学和个人发展的思考总结(十八)心流、非人情网络、穷人、人生机会、平衡计分卡
    php 判断字符串中包含重复相同的次数 array_count_values str_split max 函数组合使用
    存储过程一次性返回多个数据集,逻辑层与前端处理
    动态改变div背景颜色
    在asp.net mvc应用中使用vue.js
    angularjs单一页面中高频访问相同web api,出现阻塞和等待
    Windows安装配置OpenGrok
  • 原文地址:https://www.cnblogs.com/kim-liu/p/7495543.html
Copyright © 2011-2022 走看看