仿小米运动计步统计 让我们一起动起来
2017-03-22 本文已影响350人
ftc300_carl
本文属于装糊涂的猪原创,转载请注明出处作者
文中的Demo地址位于:https://github.com/ftc300
一直觉得小米的东西很不错,话不多说,先上小米运动计步统计效果图:
![](https://img.haomeiwen.com/i3876169/261507a89acdd41e.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;
}
上个效果图:
![](https://img.haomeiwen.com/i3876169/e3993552643d31f0.gif)
源码地址:https://github.com/ftc300/autolocatehorizontalview
网络上恶搞程序员的段子不少,“钱多话少死得早”等等,但是我们不能妥协,穿上自己的“风火轮“”撸铁去了~~(附上公司兼健身房图片一张)
![](https://img.haomeiwen.com/i3876169/5c23fd470c009d29.jpg)
或许下面这个对你的生活和健康有帮助,如果你能解锁里面所有的姿势,请收下小弟的膝盖。
倾情推荐:https://mp.weixin.qq.com/s/Wp3ymvCoTqFE137pciBxrQ
{最后的最后,希望喜欢本文的大哥大姐们,点个喜欢吧 !}
![](https://img.haomeiwen.com/i3876169/5d1963a40559aa03.png)