Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar committed Apr 19, 2018
1 parent a2ab432 commit 278a692
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ allprojects {
**Step 2. 添加项目依赖**
``` gradle
dependencies {
compile 'com.github.Othershe:GroupIndexLib:1.0.0'
compile 'com.github.Othershe:GroupIndexLib:1.0.1'
}
```
**Step 3.设置ItemDecoration**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public DivideItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
if (Utils.listIsEmpty(tags)) {
return;
}

RecyclerView.LayoutManager manager = parent.getLayoutManager();

//只处理线性垂直类型的列表
Expand All @@ -45,11 +49,14 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
if (Utils.listIsEmpty(tags)) {
return;
}
for (int i = 0; i < parent.getChildCount(); i++) {
View view = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(view);
//和getItemOffsets()里的条件判断类似
if (!Utils.listIsEmpty(tags) && (position + 1) < tags.size() && tags.get(position).equals(tags.get(position + 1))) {
if ((position + 1) < tags.size() && tags.get(position).equals(tags.get(position + 1))) {
drawDivide(c, parent, view);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public GroupHeaderItemDecoration(Context context) {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
if (Utils.listIsEmpty(tags)) {
return;
}

RecyclerView.LayoutManager manager = parent.getLayoutManager();

//只处理线性垂直类型的列表
Expand All @@ -55,20 +59,23 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle

int position = parent.getChildAdapterPosition(view);
//ItemView的position==0 或者 当前itemView的data的tag和上一个ItemView的不相等,则为当前itemView设置top 偏移量
if (!Utils.listIsEmpty(tags) && (position == 0 || !tags.get(position).equals(tags.get(position - 1)))) {
if (position == 0 || !tags.get(position).equals(tags.get(position - 1))) {
outRect.set(0, groupHeaderHeight, 0, 0);
}
}

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
if (Utils.listIsEmpty(tags)) {
return;
}
for (int i = 0; i < parent.getChildCount(); i++) {
View view = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(view);
String tag = tags.get(position);
//和getItemOffsets()里的条件判断类似,开始绘制分组的GroupHeader
if (!Utils.listIsEmpty(tags) && (position == 0 || !tag.equals(tags.get(position - 1)))) {
if (position == 0 || !tag.equals(tags.get(position - 1))) {
if (drawItemDecorationListener == null) {
drawGroupHeader(c, parent, view, tag);
} else {
Expand All @@ -81,6 +88,10 @@ public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDrawOver(c, parent, state);
if (Utils.listIsEmpty(tags)) {
return;
}

if (!show) {
return;
}
Expand All @@ -91,7 +102,7 @@ public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
View view = parent.findViewHolderForAdapterPosition(position).itemView;
//当前ItemView的data的tag和下一个ItemView的不相等,则代表将要重新绘制悬停的GroupHeader
boolean flag = false;
if (!Utils.listIsEmpty(tags) && (position + 1) < tags.size() && !tag.equals(tags.get(position + 1))) {
if ((position + 1) < tags.size() && !tag.equals(tags.get(position + 1))) {
//如果第一个可见ItemView的底部坐标小于groupHeaderHeight,则执行Canvas垂直位移操作
if (view.getBottom() <= groupHeaderHeight) {
c.save();
Expand Down

0 comments on commit 278a692

Please sign in to comment.