Skip to content

Latest commit

 

History

History
81 lines (65 loc) · 3.86 KB

README_CHINESE.md

File metadata and controls

81 lines (65 loc) · 3.86 KB

TimeLine

瀑布流时间轴,项目中主要用到了StaggerGridLayoutManager。

添加依赖

implementation 'com.vivian.widgets:TimeLineItemDecoration:1.5'

使用方法

  • RecyclerView设置StaggerGridLayoutManager
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
  • 给RecyclerView添加分割线: ItemDecoration.java。第二个参数用来设置item间隔,比如100px。
mRecyclerView.addItemDecoration(new ItemDecoration(this,100));

项目中提供了两种样式的分割线,第一种是 ItemDecoration.java(图一),第二种是DotItemDecoration.java (图二)

  DotItemDecoration mItemDecoration = new DotItemDecoration
                .Builder(this)
                .setOrientation(DotItemDecoration.VERTICAL)//如果LayoutManager设置了横向,那么这里也要设置成横向
                .setItemStyle(DotItemDecoration.STYLE_DRAW)//选择dot使用图片资源或者用canvas画
                .setTopDistance(20)//单位dp
                .setItemInterVal(10)//单位dp
                .setItemPaddingLeft(10)//如果不设置,默认和item间距一样
                .setItemPaddingRight(10)//如果不设置,默认和item间距一样
                .setDotColor(Color.WHITE)
                .setDotRadius(2)//单位dp
                .setDotPaddingTop(0)
                .setDotInItemOrientationCenter(false)//设置dot居中
                .setLineColor(Color.RED)//设置线的颜色
                .setLineWidth(1)//单位dp
                .setEndText("END")//设置结束的文字
                .setTextColor(Color.WHITE)
                .setTextSize(10)//单位sp
                .setDotPaddingText(2)//单位dp.设置最后一个点和文字之间的距离
                .setBottomDistance(40)//设置底部距离,可以延长底部线的长度
                .create();

如果需要根据item所在列数进行操作,可以实现SpanIndexListener接口

   mItemDecoration.setSpanIndexListener(new SpanIndexListener() {
            @Override
            public void onSpanIndexChange(View view, int spanIndex) {
                view.setBackgroundResource(spanIndex == 0 ? R.drawable.pop_left : R.drawable.pop_right);
            }
   });

截图

联系方式

如果有什么问题,我没有及时回复的话,可以加我微信vivian8725118,或者发邮件到1354458047@qq.com/ vivian8725118@gmail.com,我看到之后会回复的。

License

Copyright 2017 Vivian

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.