说真的自从对RecyclerView的LayoutManager有新的认识后,完全不用担心很多的复杂布局了。而且对ViewGroup测量过程也不用担心了,因为里面有LayoutManager帮我们实现了。下面就进入该篇文章的主题吧,废话不多说,直接上图更有说服力。
统一高度文本形式
不同高度文本行居中显示形式
图片形式
上面的示例图是我把ItemView分别用了TextView和ImageView。其实这些是没什么好说的,主要是如何定义这样的LayoutManager。相信大家都用过了LinearLayoutManager吧,系统提供的LayoutManager都是对齐的方式进行排版的,我们这里的flow的样式就是在排版item之前,判断了该行多余的空间还够不够显示,如果不够直接换行显示的思路。
详见TextFlowActivity、DiffHeightTextFlowActivity、PhotoFlowActivity
RecyclerView recyclerView = (RecyclerView) findViewById(flow);
FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
//设置每一个item间距
recyclerView.addItemDecoration(new SpaceItemDecoration(dp2px(10)));
recyclerView.setLayoutManager(flowLayoutManager);
recyclerView.setAdapter(new FlowAdapter());
email: [email protected]
简书: http://www.jianshu.com/users/7b186b7247c1/latest_articles
csdn: http://blog.csdn.net/u010429219/article/details/64915136