仿小米运动计步统计 让我们一起动起来

作者: ftc300_carl | 来源:发表于2017-03-22 19:38 被阅读350次

    本文属于装糊涂的猪原创,转载请注明出处作者
    文中的Demo地址位于:https://github.com/ftc300

    一直觉得小米的东西很不错,话不多说,先上小米运动计步统计效果图:


    xmyd.gif

    一、风火轮

    轮子的重要性不言而喻,这里有封装的一个横向选中的控件:
    源码地址:https://github.com/FamliarMan/AutoLocateHorizontalView
    友情参考:http://www.jianshu.com/p/640086491d1c

    二、三头六臂

    光有轮子哪吒也不行,我们还是需要再修改下源码,在滚动监听的基础上,添加了点击item,将item居中的方法:

      private void moveItemToCenter(View itemView)
            {
                DisplayMetrics dm = context.getResources().getDisplayMetrics();
                int screenWidth = dm.widthPixels;
                int[] locations = new int[2];
                itemView.getLocationInWindow(locations);
                int rbWidth = itemView.getWidth();
                smoothScrollBy((locations[0] + rbWidth / 2 - screenWidth / 2),0);
            }
    
            @Override
            public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                if (viewType == HEADER_FOOTER_TYPE) {
                    View view = new View(context);
                    headerFooterWidth = parent.getMeasuredWidth() / 2 - (parent.getMeasuredWidth() / itemCount) / 2;
                    RecyclerView.LayoutParams params = new LayoutParams(headerFooterWidth, ViewGroup.LayoutParams.MATCH_PARENT);
                    view.setLayoutParams(params);
                    return new HeaderFooterViewHolder(view);
                }
                ViewHolder holder = adapter.onCreateViewHolder(parent, viewType);
                itemView = ((IAutoLocateHorizontalView) adapter).getItemView();
                int width = parent.getMeasuredWidth() / itemCount;
                ViewGroup.LayoutParams params = itemView.getLayoutParams();
                if (params != null) {
                    params.width = width;
                    itemWidth = width;
                    itemView.setLayoutParams(params);
                }
                itemView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        moveItemToCenter(view);
                    }
                });
                return holder;
            }
    

    上个效果图:

    demo.gif
    源码地址:https://github.com/ftc300/autolocatehorizontalview

    网络上恶搞程序员的段子不少,“钱多话少死得早”等等,但是我们不能妥协,穿上自己的“风火轮“”撸铁去了~~(附上公司兼健身房图片一张)

    office.jpg
    或许下面这个对你的生活和健康有帮助,如果你能解锁里面所有的姿势,请收下小弟的膝盖。
    倾情推荐:https://mp.weixin.qq.com/s/Wp3ymvCoTqFE137pciBxrQ

    {最后的最后,希望喜欢本文的大哥大姐们,点个喜欢吧 !}


    维护个公众号试试吧.png

    相关文章

      网友评论

      本文标题:仿小米运动计步统计 让我们一起动起来

      本文链接:https://www.haomeiwen.com/subject/pymknttx.html